@@ -445,27 +445,27 @@ public function getImapBox()
445
445
446
446
/**
447
447
* Adds an attachment
448
- *
449
- * If a filename is not provided and the attachment is a message/rfc822
450
- * email, parse the Subject line and use it as the filename. If the Subject
451
- * line is blank or illegible, use a default filename (like Gmail and some
448
+ *
449
+ * If a filename is not provided and the attachment is a message/rfc822
450
+ * email, parse the Subject line and use it as the filename. If the Subject
451
+ * line is blank or illegible, use a default filename (like Gmail and some
452
452
* desktop clients do)
453
453
*
454
- * @param array $parameters
455
- * @param \stdClass $structure
456
- * @param string $partIdentifier
457
- * @return boolean Successful attachment of file
454
+ * @param array $parameters
455
+ * @param \stdClass $structure
456
+ * @param string $partIdentifier
457
+ * @return boolean Successful attachment of file
458
458
*/
459
459
protected function addAttachment ($ parameters , $ structure , $ partIdentifier )
460
460
{
461
461
if (!(isset ($ parameters ["name " ]) || isset ($ parameters ["filename " ])) && $ structure ->type == self ::TYPE_MESSAGE ) {
462
462
$ body = isset ($ partIdentifier ) ?
463
463
imap_fetchbody ($ this ->imapStream , $ this ->uid , $ partIdentifier , FT_UID )
464
464
: imap_body ($ this ->imapStream , $ this ->uid , FT_UID );
465
-
465
+
466
466
$ headers = iconv_mime_decode_headers ($ body , 0 , self ::$ charset );
467
467
$ filename = !empty ($ headers ["Subject " ]) ? $ this ->makeFilenameSafe ($ headers ["Subject " ]) : "email " ;
468
-
468
+
469
469
$ dpar = new \stdClass ();
470
470
$ dpar ->attribute = "filename " ;
471
471
$ dpar ->value = str_replace (array ("\r" , "\n" ), '' , $ filename ) . ".eml " ;
@@ -483,26 +483,26 @@ protected function addAttachment($parameters, $structure, $partIdentifier)
483
483
}
484
484
485
485
/**
486
- * This function extracts the body of an email part, strips harmful
487
- * Outlook-specific strings from it, processes any encoded one-liners,
488
- * decodes it, converts it to the charset of the parent message, and
486
+ * This function extracts the body of an email part, strips harmful
487
+ * Outlook-specific strings from it, processes any encoded one-liners,
488
+ * decodes it, converts it to the charset of the parent message, and
489
489
* returns the result.
490
490
*
491
- * @param array $parameters
492
- * @param \stdClass $structure
493
- * @param string $partIdentifier
491
+ * @param array $parameters
492
+ * @param \stdClass $structure
493
+ * @param string $partIdentifier
494
494
* @return string
495
495
*/
496
496
protected function processBody ($ structure , $ partIdentifier )
497
497
{
498
498
$ rawBody = isset ($ partIdentifier ) ?
499
499
imap_fetchbody ($ this ->imapStream , $ this ->uid , $ partIdentifier , FT_UID )
500
500
: imap_body ($ this ->imapStream , $ this ->uid , FT_UID );
501
-
501
+
502
502
$ bodyNoOutlook = $ this ->stripOutlookSpecificStrings ($ rawBody );
503
-
503
+
504
504
$ decodedBody = self ::decode ($ bodyNoOutlook , $ structure ->encoding );
505
-
505
+
506
506
$ inCharset = $ inCharset = mb_detect_encoding ($ decodedBody , array (
507
507
"US-ASCII " ,
508
508
"ISO-8859-1 " ,
@@ -520,41 +520,41 @@ protected function processBody($structure, $partIdentifier)
520
520
"UCS2 " ,
521
521
"UCS4 " )
522
522
);
523
-
523
+
524
524
if ($ inCharset && $ inCharset !== self ::$ charset ) {
525
525
$ decodedBody = iconv ($ inCharset , self ::$ charset , $ decodedBody );
526
526
}
527
527
528
528
return $ decodedBody ;
529
529
}
530
-
530
+
531
531
/**
532
- * Removes "Thread-Index:" line from the message body which is placed there
532
+ * Removes "Thread-Index:" line from the message body which is placed there
533
533
* by Outlook and messes up the other processing steps.
534
- *
535
- * @param string $messageBody
534
+ *
535
+ * @param string $messageBody
536
536
* @return string
537
537
*/
538
538
protected function stripOutlookSpecificStrings ($ bodyBefore )
539
539
{
540
540
$ bodyAfter = preg_replace ('/Thread-Index:.*$/m ' , "" , $ bodyBefore );
541
-
541
+
542
542
return $ bodyAfter ;
543
543
}
544
-
544
+
545
545
/**
546
- * This function takes in a string to be used as a filename and replaces
547
- * any dangerous characters with underscores to ensure compatibility with
546
+ * This function takes in a string to be used as a filename and replaces
547
+ * any dangerous characters with underscores to ensure compatibility with
548
548
* various file systems
549
- *
550
- * @param string $oldName
549
+ *
550
+ * @param string $oldName
551
551
* @return string
552
552
*/
553
553
protected function makeFilenameSafe ($ oldName )
554
554
{
555
555
return preg_replace ('/[<>"{}| \\\^\[\]`;\/\?:@&=$,]/ ' ,"_ " , $ oldName );
556
556
}
557
-
557
+
558
558
/**
559
559
* This function takes in a structure and identifier and processes that part of the message. If that portion of the
560
560
* message has its own subparts, those are recursively processed using this function.
@@ -565,7 +565,7 @@ protected function makeFilenameSafe($oldName)
565
565
protected function processStructure ($ structure , $ partIdentifier = null )
566
566
{
567
567
$ attached = false ;
568
-
568
+
569
569
// TODO: Get HTML attachments working, too!
570
570
if (isset ($ structure ->disposition ) && $ structure ->disposition == "attachment " ) {
571
571
$ parameters = self ::getParametersFromStructure ($ structure );
@@ -632,7 +632,7 @@ public static function decode($data, $encoding)
632
632
return $ data ;
633
633
}
634
634
}
635
-
635
+
636
636
/**
637
637
* This function returns the body type that an imap integer maps to.
638
638
*
0 commit comments