Example #1
0
 public static function fromTemplate($rawmessage, $type, $refwtemplate, $emails = [])
 {
     $mail = new self($rawmessage);
     list($html, $content) = $mail->extractContent();
     $mail_new = self::fromData($type == 2 ? $mail->extractAttachments() : [], $html ? \Zeyon\encodeHtml(sprintf($refwtemplate, $mail->sender, $mail->to, date('r', $mail->date), $mail->subject)) . $content : sprintf($refwtemplate, $mail->sender, $mail->to, date('r', $mail->date), $mail->subject) . ($type == 2 ? $content : preg_replace('/(^|\\r\\n|\\r|\\n)-- (\\r\\n|\\r|\\n).*/s', '', $content, 1)), $html);
     $mail_new->subject = ($type == 2 ? 'Fw' : 'Re') . ': ' . preg_replace('/^(?:(?:Re|Fw):\\s*)+/i', '', trim($mail->subject), 1);
     if ($type != 2) {
         $senders = self::extractSpecific("{$mail->to},{$mail->cc}", $emails) and $mail_new->sender = $senders[0];
         $mail_new->to = $mail->replyto == '' ? $mail->sender : $mail->replyto;
         if ($type == 0) {
             if ($mail->to != '') {
                 $mail_new->to == '' or $mail_new->to .= ', ';
                 $mail_new->to .= $mail->to;
             }
             $mail_new->to = join(', ', self::extractSpecific($mail_new->to, $emails, true));
             $mail_new->cc = join(', ', self::extractSpecific($mail->cc, $emails, true));
         }
     }
     return $mail_new;
 }