File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313use ZBateson \MailMimeParser \Header \Part \ContainerPart ;
1414use ZBateson \MailMimeParser \Header \Part \NameValuePart ;
1515use ZBateson \MailMimeParser \Message as MailMimeMessage ;
16- use ZBateson \MailMimeParser \Message \MimePart ;
1716
1817trait HasParsedMessage
1918{
@@ -119,14 +118,27 @@ public function bcc(): array
119118 */
120119 public function attachments (): array
121120 {
122- return array_map (function (MimePart $ part ) {
123- return new Attachment (
124- $ part ->getFilename (),
125- $ part ->getContentId (),
126- $ part ->getContentType (),
127- $ part ->getContentStream () ?? Utils::streamFor ('' ),
128- );
129- }, $ this ->parse ()->getAllAttachmentParts ());
121+ $ attachments = [];
122+
123+ foreach ($ this ->parse ()->getAllAttachmentParts () as $ part ) {
124+ // If the attachment's content type is message/rfc822, we're
125+ // working with a forwarded message. We will parse the
126+ // forwarded message and merge in its attachments.
127+ if (strtolower ($ part ->getContentType ()) === 'message/rfc822 ' ) {
128+ $ message = new FileMessage ($ part ->getContent ());
129+
130+ $ attachments = array_merge ($ attachments , $ message ->attachments ());
131+ } else {
132+ $ attachments [] = new Attachment (
133+ $ part ->getFilename (),
134+ $ part ->getContentId (),
135+ $ part ->getContentType (),
136+ $ part ->getContentStream () ?? Utils::streamFor ('' ),
137+ );
138+ }
139+ }
140+
141+ return $ attachments ;
130142 }
131143
132144 /**
You can’t perform that action at this time.
0 commit comments