示例#1
0
 function recordInbound()
 {
     $strJson = file_get_contents("php://input");
     try {
         $arrResponse = Convert::json2array($strJson);
         if ($savedMessage = PostmarkMessage::get()->filter('MessageID', $arrResponse['MessageID'])->first()) {
             return;
         }
         $hash = $arrResponse['ToFull'][0]['MailboxHash'];
         $hashParts = explode('+', $hash);
         $lastMessage = PostmarkMessage::get()->filter(array('UserHash' => $hashParts[0], 'MessageHash' => $hashParts[1]))->first();
         $fromCustomer = PostmarkHelper::find_or_make_client($arrResponse['From']);
         $inboundSignature = null;
         if ($lastMessage) {
             $inboundSignature = $lastMessage->From();
         } else {
             if (!$lastMessage && isset($arrResponse['To'])) {
                 $inboundSignature = PostmarkSignature::get()->filter('Email', $arrResponse['To'])->first();
             }
         }
         if (!$inboundSignature) {
             $inboundSignature = PostmarkSignature::get()->filter('IsDefault', 1)->first();
         }
         $message = new PostmarkMessage(array('Subject' => $arrResponse['Subject'], 'Message' => $arrResponse['HtmlBody'], 'ToID' => 0, 'MessageID' => $arrResponse['MessageID'], 'InReplyToID' => $lastMessage ? $lastMessage->ID : 0, 'FromCustomerID' => $fromCustomer ? $fromCustomer->ID : 0, 'InboundToID' => $inboundSignature ? $inboundSignature->ID : 0));
         $message->write();
         if (isset($arrResponse['Attachments']) && count($arrResponse['Attachments'])) {
             foreach ($arrResponse['Attachments'] as $attachment) {
                 $attachmentObject = new Attachment(array('Content' => $attachment['Content'], 'FileName' => $attachment['Name'], 'ContentType' => $attachment['ContentType'], 'Length' => $attachment['ContentLength'], 'ContentID' => $attachment['ContentID'], 'PostmarkMessageID' => $message->ID));
                 $attachmentObject->write();
             }
         }
     } catch (Exception $e) {
     }
     return 'OK';
 }
 public function read($request)
 {
     if (!$this->record->canView()) {
         $this->httpError(403);
     }
     if (isset($_GET['m'])) {
         $message = PostmarkMessage::get()->byID($_GET['m']);
         if (!$message->Read) {
             $message->Read = 1;
             $message->write();
         }
     }
 }
 public function sendPostmarked($to, $from, $subject, $htmlContent, $plainContent, $attachedFiles, $customheaders, $signature = null)
 {
     if (empty($signature)) {
         $signature = PostmarkSignature::get()->filter('Email', $from)->first();
     }
     if (!$signature) {
         $signature = PostmarkSignature::get()->filter('IsDefault', 1)->first();
     }
     $client = new PostmarkClient(SiteConfig::current_site_config()->PostmarkToken);
     $customerIDs = PostmarkHelper::client_list()->filter('Email', explode(',', $to))->column('ID');
     $message = null;
     if (is_array($customerIDs) && !empty($customerIDs) && self::$record_emails) {
         $message = new PostmarkMessage(array('Subject' => $subject, 'Message' => $htmlContent, 'PlainMessage' => $plainContent, 'ToID' => implode(',', $customerIDs), 'FromID' => $signature ? $signature->ID : $signature, 'InReplyToID' => self::$reply_to_message));
         $message->write();
     }
     $cc = null;
     if (isset($customheaders['CC'])) {
         $cc = $customheaders['CC'];
         unset($customheaders['CC']);
     }
     if (isset($customheaders['cc'])) {
         $cc = $customheaders['cc'];
         unset($customheaders['cc']);
     }
     $bcc = null;
     if (isset($customheaders['Bcc'])) {
         $bcc = $customheaders['Bcc'];
         unset($customheaders['Bcc']);
     }
     if (isset($customheaders['BCC'])) {
         $bcc = $customheaders['bcc'];
         unset($customheaders['BCC']);
     }
     if (isset($customheaders['bcc'])) {
         $bcc = $customheaders['bcc'];
         unset($customheaders['bcc']);
     }
     $attachments = null;
     if ($attachedFiles && is_array($attachedFiles)) {
         $attachments = array();
         foreach ($attachedFiles as $attachment) {
             $attachments[] = PostmarkAttachment::fromRawData($attachment['contents'], $attachment['filename'], $attachment['mimetype']);
             if (is_array($customerIDs) && !empty($customerIDs) && self::$record_emails) {
                 $postmarkAttachment = new Attachment(array('Content' => base64_encode($attachment['contents']), 'FileName' => $attachment['filename'], 'ContentType' => $attachment['mimetype'], 'PostmarkMessageID' => $message->ID, 'Length' => strlen($attachment['contents'])));
                 $postmarkAttachment->write();
             }
         }
     }
     $arrangedHeaders = null;
     if ($customheaders && is_array($customheaders) && count($customheaders)) {
         $arrangedHeaders = array();
         foreach ($customheaders as $key => $val) {
             $arrangedHeaders[$key] = $val;
         }
     }
     $sendResult = $client->sendEmail($signature ? $signature->Email : $from, $to, $subject, $htmlContent, $plainContent, null, true, $message ? $message->replyToEmailAddress() : $from, $cc, $bcc, $arrangedHeaders, $attachments);
     if (is_array($customerIDs) && !empty($customerIDs) && self::$record_emails && $sendResult->__get('message') == 'OK') {
         $message->MessageID = $sendResult->__get('messageid');
         $message->write();
     }
     return $sendResult->__get('message') == 'OK';
 }
 public function getTotalMessages()
 {
     $list = PostmarkMessage::get()->filter(array('FromCustomerID' => $this->owner->ID));
     return $list->count();
 }
示例#5
0
 public function Children()
 {
     return PostmarkMessage::get()->filter('InReplyToID', $this->ID);
 }