@@ -397,13 +397,14 @@ public function getQuotaUsage() {
397397 return $ quota ;
398398 }
399399
400- /**
401- * Get mail data
402- *
403- * @param $mailId
404- * @return IncomingMail
405- */
406- public function getMail ($ mailId ) {
400+ /**
401+ * Get mail data
402+ *
403+ * @param $mailId
404+ * @param bool $markAsSeen
405+ * @return IncomingMail
406+ */
407+ public function getMail ($ mailId , $ markAsSeen = true ) {
407408 $ head = imap_rfc822_parse_headers (imap_fetchheader ($ this ->getImapStream (), $ mailId , FT_UID ));
408409
409410 $ mail = new IncomingMail ();
@@ -441,19 +442,23 @@ public function getMail($mailId) {
441442 $ mailStructure = imap_fetchstructure ($ this ->getImapStream (), $ mailId , FT_UID );
442443
443444 if (empty ($ mailStructure ->parts )) {
444- $ this ->initMailPart ($ mail , $ mailStructure , 0 );
445+ $ this ->initMailPart ($ mail , $ mailStructure , 0 , $ markAsSeen );
445446 }
446447 else {
447448 foreach ($ mailStructure ->parts as $ partNum => $ partStructure ) {
448- $ this ->initMailPart ($ mail , $ partStructure , $ partNum + 1 );
449+ $ this ->initMailPart ($ mail , $ partStructure , $ partNum + 1 , $ markAsSeen );
449450 }
450451 }
451452
452453 return $ mail ;
453454 }
454455
455- protected function initMailPart (IncomingMail $ mail , $ partStructure , $ partNum ) {
456- $ data = $ partNum ? imap_fetchbody ($ this ->getImapStream (), $ mail ->id , $ partNum , FT_UID ) : imap_body ($ this ->getImapStream (), $ mail ->id , FT_UID );
456+ protected function initMailPart (IncomingMail $ mail , $ partStructure , $ partNum , $ markAsSeen = true ) {
457+ $ options = FT_UID ;
458+ if (!$ markAsSeen ) {
459+ $ options |= FT_PEEK ;
460+ }
461+ $ data = $ partNum ? imap_fetchbody ($ this ->getImapStream (), $ mail ->id , $ partNum , $ options ) : imap_body ($ this ->getImapStream (), $ mail ->id , $ options );
457462
458463 if ($ partStructure ->encoding == 1 ) {
459464 $ data = imap_utf8 ($ data );
@@ -535,10 +540,10 @@ protected function initMailPart(IncomingMail $mail, $partStructure, $partNum) {
535540 if (!empty ($ partStructure ->parts )) {
536541 foreach ($ partStructure ->parts as $ subPartNum => $ subPartStructure ) {
537542 if ($ partStructure ->type == 2 && $ partStructure ->subtype == 'RFC822 ' ) {
538- $ this ->initMailPart ($ mail , $ subPartStructure , $ partNum );
543+ $ this ->initMailPart ($ mail , $ subPartStructure , $ partNum, $ markAsSeen );
539544 }
540545 else {
541- $ this ->initMailPart ($ mail , $ subPartStructure , $ partNum . '. ' . ($ subPartNum + 1 ));
546+ $ this ->initMailPart ($ mail , $ subPartStructure , $ partNum . '. ' . ($ subPartNum + 1 ), $ markAsSeen );
542547 }
543548 }
544549 }
0 commit comments