Ejemplo n.º 1
0
 /**
  * @param IMessage $message
  * @param int|null $previousUID
  * @return int
  */
 public function saveDraft(IMessage $message, $previousUID)
 {
     // build mime body
     $from = new Horde_Mail_Rfc822_Address($message->getFrom());
     $from->personal = $this->getName();
     $headers = ['From' => $from, 'To' => $message->getToList(), 'Cc' => $message->getCCList(), 'Bcc' => $message->getBCCList(), 'Subject' => $message->getSubject(), 'Date' => Horde_Mime_Headers_Date::create()];
     $mail = new Horde_Mime_Mail();
     $mail->addHeaders($headers);
     $mail->setBody($message->getContent());
     // create transport and save message
     // save the message in the drafts folder
     $draftsFolder = $this->getDraftsFolder();
     /** @var resource $raw */
     $raw = $mail->getRaw();
     $newUid = $draftsFolder->saveDraft(stream_get_contents($raw));
     // delete old version if one exists
     if (!is_null($previousUID)) {
         $draftsFolder->setMessageFlag($previousUID, \Horde_Imap_Client::FLAG_DELETED, true);
         $this->deleteDraft($previousUID);
     }
     return $newUid;
 }
Ejemplo n.º 2
0
 /**
  * Send a new message or reply to an existing message
  *
  * @param IMessage $message
  * @param int|null $draftUID
  */
 public function sendMessage(IMessage $message, $draftUID)
 {
     // build mime body
     $from = new Horde_Mail_Rfc822_Address($message->getFrom());
     $from->personal = $this->getName();
     $headers = ['From' => $from, 'To' => $message->getToList(), 'Cc' => $message->getCCList(), 'Bcc' => $message->getBCCList(), 'Subject' => $message->getSubject()];
     if (!is_null($message->getRepliedMessage())) {
         $headers['In-Reply-To'] = $message->getRepliedMessage()->getMessageId();
     }
     $mail = new Horde_Mime_Mail();
     $mail->addHeaders($headers);
     $mail->setBody($message->getContent());
     // Append attachments
     foreach ($message->getAttachments() as $attachment) {
         $mail->addMimePart($attachment);
     }
     // Send the message
     $transport = $this->createTransport();
     $mail->send($transport);
     // Save the message in the sent folder
     $sentFolder = $this->getSentFolder();
     /** @var resource $raw */
     $raw = stream_get_contents($mail->getRaw());
     $sentFolder->saveMessage($raw, [Horde_Imap_Client::FLAG_SEEN]);
     // Delete draft if one exists
     if (!is_null($draftUID)) {
         $draftsFolder = $this->getDraftsFolder();
         $draftsFolder->setMessageFlag($draftUID, Horde_Imap_Client::FLAG_DELETED, true);
         $this->deleteDraft($draftUID);
     }
 }