@@ -43,6 +43,13 @@ class Message {
4343 */
4444 public $ fetch_options = null ;
4545
46+ /**
47+ * Fetch attachments options
48+ *
49+ * @var bool
50+ */
51+ public $ fetch_attachment = null ;
52+
4653 /**
4754 * @var int $msglist
4855 */
@@ -128,9 +135,11 @@ class Message {
128135 * @param Client $client
129136 * @param integer|null $fetch_options
130137 * @param boolean $parse_body
138+ * @param boolean $fetch_attachment
131139 */
132- public function __construct ($ uid , $ msglist , Client $ client , $ fetch_options = null , $ parse_body = false ) {
140+ public function __construct ($ uid , $ msglist , Client $ client , $ fetch_options = null , $ parse_body = false , $ fetch_attachment = false ) {
133141 $ this ->setFetchOption ($ fetch_options );
142+ $ this ->setFetchAttachment ($ fetch_attachment );
134143
135144 $ this ->attachments = AttachmentCollection::make ([]);
136145
@@ -371,8 +380,8 @@ public function parseBody() {
371380 * @param mixed $partNumber
372381 */
373382 private function fetchStructure ($ structure , $ partNumber = null ) {
374- if ($ structure ->type == self ::TYPE_TEXT &&
375- ($ structure ->ifdisposition == 0 ||
383+ if ($ structure ->type == self ::TYPE_TEXT &&
384+ ($ structure ->ifdisposition == 0 ||
376385 ($ structure ->ifdisposition == 1 && !isset ($ structure ->parts ) && $ partNumber == null )
377386 )
378387 ) {
@@ -421,7 +430,9 @@ private function fetchStructure($structure, $partNumber = null) {
421430 $ this ->fetchStructure ($ subStruct , $ prefix .($ index + 1 ));
422431 }
423432 } else {
424- $ this ->fetchAttachment ($ structure , $ partNumber );
433+ if ($ this ->fetch_attachment === true ) {
434+ $ this ->fetchAttachment ($ structure , $ partNumber );
435+ }
425436 }
426437 }
427438
@@ -461,6 +472,23 @@ public function setFetchOption($option) {
461472
462473 return $ this ;
463474 }
475+ /**
476+ * Fail proof setter for $fetch_attachment
477+ *
478+ * @param $option
479+ *
480+ * @return $this
481+ */
482+ public function setFetchAttachment ($ option ) {
483+ if (is_bool ($ option ) == true ) {
484+ $ this ->fetch_attachment = $ option ;
485+ } elseif (is_null ($ option ) == true ) {
486+ $ config = config ('imap.options.attachments ' , false );
487+ $ this ->fetch_attachment = is_bool ($ config ) ? $ config : false ;
488+ }
489+
490+ return $ this ;
491+ }
464492
465493 /**
466494 * Decode a given string
0 commit comments