* @author Clement Wong * @author Jan-Christoph Borchardt * @author Lukas Reschke * @author matiasdelellis * @author Robin McCorkell * @author Thomas Imbreckx * @author Thomas I * @author Thomas Mueller * @author Thomas Müller * @author Maximilian Zellhofer * * Mail * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see * */ namespace OCA\Mail; use Horde_Imap_Client; use Horde_Imap_Client_Mailbox; use Horde_Imap_Client_Socket; use OCA\Mail\Model\IMAPMessage; class Mailbox { /** * @var Horde_Imap_Client_Socket */ protected $conn; /** * @var Horde_Imap_Client_Mailbox */ protected $mailBox; /** * @param Horde_Imap_Client_Socket $conn * @param Horde_Imap_Client_Mailbox $mailBox */ public function __construct($conn, $mailBox) { $this->conn = $conn; $this->mailBox = $mailBox; } /** * @param int $uid * @param bool $loadHtmlMessageBody * * @return IMAPMessage */ public function getMessage(int $uid, bool $loadHtmlMessageBody = false) { return new IMAPMessage($this->conn, $this->mailBox, $uid, null, $loadHtmlMessageBody); } /** * @param int $messageUid * @param string $attachmentId * * @return Attachment */ public function getAttachment(int $messageUid, string $attachmentId): Attachment { return new Attachment($this->conn, $this->mailBox, $messageUid, $attachmentId); } /** * @param string $rawBody * @param array $flags * @return array UIDs * * @deprecated only used for testing */ public function saveMessage($rawBody, $flags = []) { $uids = $this->conn->append($this->mailBox, [ [ 'data' => $rawBody, 'flags' => $flags ] ])->ids; return reset($uids); } }