Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Mailbox.php « lib - github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 777f82ee4cbecb1989fb90433afd3a10ef37f709 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php

/**
 * @author Christoph Wurst <christoph@winzerhof-wurst.at>
 * @author Clement Wong <mail@clement.hk>
 * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
 * @author Lukas Reschke <lukas@owncloud.com>
 * @author matiasdelellis <mati86dl@gmail.com>
 * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
 * @author Thomas Imbreckx <zinks@iozero.be>
 * @author Thomas I <thomas@oatr.be>
 * @author Thomas Mueller <thomas.mueller@tmit.eu>
 * @author Thomas Müller <thomas.mueller@tmit.eu>
 * @author Maximilian Zellhofer <max.zellhofer@gmail.com>
 *
 * 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 <http://www.gnu.org/licenses/>
 *
 */

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<int> 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);
	}
}