Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions lib/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,30 @@

namespace OCA\Mail;

use Horde_Imap_Client;
use Horde_Imap_Client_Exception;
use Horde_Imap_Client_Ids;
use Horde_Imap_Client_Mailbox;
use Horde_Imap_Client_Socket;
use Horde_Imap_Client;
use Horde_Mail_Rfc822_Address;
use Horde_Mail_Rfc822_List;
use Horde_Mail_Transport;
use Horde_Mail_Transport_Mail;
use Horde_Mail_Transport_Smtphorde;
use Horde_Mime_Headers_Date;
use Horde_Mime_Mail;
use Horde_Mime_Part;
use OC;
use OCA\Mail\Cache\Cache;
use OCA\Mail\Db\Alias;
use OCA\Mail\Db\MailAccount;
use OCA\Mail\Model\IMessage;
use OCA\Mail\Model\Message;
use OCA\Mail\Model\ReplyMessage;
use OCA\Mail\Service\IAccount;
use OCP\IConfig;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\Security\ICrypto;
use OCA\Mail\Db\Alias;

class Account implements IAccount {

Expand Down Expand Up @@ -84,9 +87,9 @@ class Account implements IAccount {
public function __construct(MailAccount $account) {
$this->account = $account;
$this->mailboxes = null;
$this->crypto = \OC::$server->getCrypto();
$this->config = \OC::$server->getConfig();
$this->memcacheFactory = \OC::$server->getMemcacheFactory();
$this->crypto = OC::$server->getCrypto();
$this->config = OC::$server->getConfig();
$this->memcacheFactory = OC::$server->getMemcacheFactory();
$this->alias = null;
}

Expand Down Expand Up @@ -312,7 +315,7 @@ protected function listMailboxes($pattern = '*') {

/**
* @param string $folderId
* @return \OCA\Mail\Mailbox
* @return Mailbox
*/
public function getMailbox($folderId) {
$conn = $this->getImapConnection();
Expand Down Expand Up @@ -343,8 +346,7 @@ public function getMailboxes() {
/**
* @return array
*/
public function getListArray() {

public function jsonSerialize() {
$folders = [];
$mailBoxes = $this->getMailboxes();
$mailBoxNames = array_map(function($mb) {
Expand All @@ -358,7 +360,7 @@ public function getListArray() {
$status = $this->getImapConnection()->status($mailBoxNames);
foreach ($mailBoxes as $mailbox) {
$s = isset($status[$mailbox->getFolderId()]) ? $status[$mailbox->getFolderId()] : null;
$folders[] = $mailbox->getListArray($this->getId(), $s);
$folders[] = $mailbox->serialize($this->getId(), $s);
}
$delimiter = reset($folders)['delimiter'];
return [
Expand Down Expand Up @@ -505,13 +507,13 @@ public function deleteMessage($sourceFolderId, $messageId) {
$this->getImapConnection()->expunge($hordeSourceMailBox,
array('ids' => $hordeMessageIds, 'delete' => true));

\OC::$server->getLogger()->info("Message expunged: {message} from mailbox {mailbox}",
OC::$server->getLogger()->info("Message expunged: {message} from mailbox {mailbox}",
array('message' => $messageId, 'mailbox' => $sourceFolderId));
} else {
$this->getImapConnection()->copy($hordeSourceMailBox, $hordeTrashMailBox,
array('create' => $createTrash, 'move' => true, 'ids' => $hordeMessageIds));

\OC::$server->getLogger()->info("Message moved to trash: {message} from mailbox {mailbox}",
OC::$server->getLogger()->info("Message moved to trash: {message} from mailbox {mailbox}",
array('message' => $messageId, 'mailbox' => $sourceFolderId, 'app' => 'mail'));
}
}
Expand Down Expand Up @@ -586,7 +588,7 @@ protected function getSpecialFolder($role, $guessBest=true) {
*/
protected function localizeSpecialMailboxes() {

$l = \OC::$server->getL10N('mail');
$l = OC::$server->getL10N('mail');
$map = [
// TRANSLATORS: translated mail box name
'inbox' => $l->t('Inbox'),
Expand Down Expand Up @@ -723,7 +725,7 @@ public function getChangedMailboxes($query) {
$newMessages = $m->getMessagesSince($uidNext, $s['uidnext']);
// only trigger updates in case new messages are actually available
if (!empty($newMessages)) {
$changedBoxes[$folderId] = $m->getListArray($this->getId(), $s);
$changedBoxes[$folderId] = $m->serialize($this->getId(), $s);
$changedBoxes[$folderId]['messages'] = $newMessages;
$newUnreadMessages = array_filter($newMessages, function($m) {
return $m['flags']['unseen'];
Expand All @@ -738,7 +740,7 @@ public function getChangedMailboxes($query) {
}

/**
* @throws \Horde_Imap_Client_Exception
* @throws Horde_Imap_Client_Exception
*/
public function reconnect() {
$this->mailboxes = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/controller/folderscontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct($appName, IRequest $request, AccountService $account
*/
public function index($accountId) {
$account = $this->accountService->find($this->currentUserId, $accountId);
$json = $account->getListArray();
$json = $account->jsonSerialize();

$folders = array_filter($json['folders'], function($folder){
return is_null($folder['parent']);
Expand Down
4 changes: 2 additions & 2 deletions lib/mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function getMessages($from = 0, $count = 2, $filter = '') {
foreach ($headers->ids() as $message_id) {
$header = $headers[$message_id];
$message = new IMAPMessage($this->conn, $this->mailBox, $message_id, $header);
$messages[] = $message->getListArray();
$messages[] = $message->jsonSerialize();
}
ob_get_clean();

Expand Down Expand Up @@ -288,7 +288,7 @@ public function setDisplayName($displayName) {
* @param integer $accountId
* @return array
*/
public function getListArray($accountId, $status = null) {
public function serialize($accountId, $status = null) {
$displayName = $this->getDisplayName();
try {
if (is_null($status)) {
Expand Down
85 changes: 47 additions & 38 deletions lib/model/imapmessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,23 @@
use Closure;
use Exception;
use Horde_Imap_Client;
use Horde_Imap_Client_Data_Envelope;
use Horde_Imap_Client_Data_Fetch;
use Horde_Imap_Client_DateTime;
use Horde_Imap_Client_Fetch_Query;
use Horde_Imap_Client_Ids;
use Horde_Imap_Client_Mailbox;
use Horde_Imap_Client_Socket;
use Horde_Mail_Rfc822_List;
use OCP\Files\File;
use Horde_Mime_Part;
use JsonSerializable;
use OC;
use OCA\Mail\Service\Html;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Files\File;
use OCP\Util;

class IMAPMessage implements IMessage {
class IMAPMessage implements IMessage, JsonSerializable {

use ConvertAddresses;

Expand All @@ -49,8 +58,8 @@ class IMAPMessage implements IMessage {
private $uid;

/**
* @param \Horde_Imap_Client_Socket|null $conn
* @param \Horde_Imap_Client_Mailbox $mailBox
* @param Horde_Imap_Client_Socket|null $conn
* @param Horde_Imap_Client_Mailbox $mailBox
* @param integer $messageId
* @param \Horde_Imap_Client_Data_Fetch|null $fetch
* @param boolean $loadHtmlMessage
Expand All @@ -65,8 +74,8 @@ public function __construct($conn, $mailBox, $messageId, $fetch=null,

$this->htmlService = $htmlService;
if (is_null($htmlService)) {
$urlGenerator = \OC::$server->getURLGenerator();
$request = \OC::$server->getRequest();
$urlGenerator = OC::$server->getURLGenerator();
$request = OC::$server->getRequest();
$this->htmlService = new Html($urlGenerator, $request);
}

Expand All @@ -86,12 +95,12 @@ public function __construct($conn, $mailBox, $messageId, $fetch=null,
private $hasHtmlMessage = false;

/**
* @var \Horde_Imap_Client_Socket
* @var Horde_Imap_Client_Socket
*/
private $conn;

/**
* @var \Horde_Imap_Client_Mailbox
* @var Horde_Imap_Client_Mailbox
*/
private $mailBox;
private $messageId;
Expand Down Expand Up @@ -144,7 +153,7 @@ public function setFlags(array $flags) {
}

/**
* @return \Horde_Imap_Client_Data_Envelope
* @return Horde_Imap_Client_Data_Envelope
*/
public function getEnvelope() {
return $this->fetch->getEnvelope();
Expand Down Expand Up @@ -296,7 +305,7 @@ public function setSubject($subject) {
}

/**
* @return \Horde_Imap_Client_DateTime
* @return Horde_Imap_Client_DateTime
*/
public function getSentDate() {
return $this->fetch->getImapDate();
Expand All @@ -307,13 +316,13 @@ public function getSize() {
}

/**
* @param \Horde_Mime_Part $part
* @param Horde_Mime_Part $part
* @return bool
*/
private function hasAttachments($part) {
foreach($part->getParts() as $p) {
/**
* @var \Horde_Mime_Part $p
* @var Horde_Mime_Part $p
*/
$filename = $p->getName();

Expand All @@ -339,7 +348,7 @@ private function hasAttachments($part) {
private function loadMessageBodies() {
$headers = [];

$fetch_query = new \Horde_Imap_Client_Fetch_Query();
$fetch_query = new Horde_Imap_Client_Fetch_Query();
$fetch_query->envelope();
$fetch_query->structure();
$fetch_query->flags();
Expand All @@ -359,7 +368,7 @@ private function loadMessageBodies() {
]);

// $list is an array of Horde_Imap_Client_Data_Fetch objects.
$ids = new \Horde_Imap_Client_Ids($this->messageId);
$ids = new Horde_Imap_Client_Ids($this->messageId);
$headers = $this->conn->fetch($this->mailBox, $fetch_query, ['ids' => $ids]);
/** @var $fetch \Horde_Imap_Client_Data_Fetch */
$fetch = $headers[$this->messageId];
Expand Down Expand Up @@ -452,7 +461,7 @@ private function getPart($p, $partNo) {
public function getFullMessage($ownMail, $specialRole=null) {
$mailBody = $this->plainMessage;

$data = $this->getListArray();
$data = $this->jsonSerialize();
if ($this->hasHtmlMessage) {
$data['hasHtmlBody'] = true;
} else {
Expand All @@ -474,23 +483,23 @@ public function getFullMessage($ownMail, $specialRole=null) {
return $data;
}

public function getListArray() {
$data = [];
$data['id'] = $this->getUid();
$data['from'] = $this->getFrom();
$data['fromEmail'] = $this->getFromEmail();
$data['fromList'] = $this->getFromList();
$data['to'] = $this->getTo();
$data['toEmail'] = $this->getToEmail();
$data['toList'] = $this->getToList(true);
$data['subject'] = $this->getSubject();
$data['date'] = \OC::$server->getDateTimeFormatter()->formatDate($this->getSentDate()->format('U'));
$data['size'] = Util::humanFileSize($this->getSize());
$data['flags'] = $this->getFlags();
$data['dateInt'] = $this->getSentDate()->getTimestamp();
$data['dateIso'] = $this->getSentDate()->format('c');
$data['ccList'] = $this->getCCList(true);
return $data;
public function jsonSerialize() {
return [
'id' => $this->getUid(),
'from' => $this->getFrom(),
'fromEmail' => $this->getFromEmail(),
'fromList' => $this->getFromList(),
'to' => $this->getTo(),
'toEmail' => $this->getToEmail(),
'toList' => $this->getToList(true),
'subject' => $this->getSubject(),
'date' => OC::$server->getDateTimeFormatter()->formatDate($this->getSentDate()->format('U')),
'size' => Util::humanFileSize($this->getSize()),
'flags' => $this->getFlags(),
'dateInt' => $this->getSentDate()->getTimestamp(),
'dateIso' => $this->getSentDate()->format('c'),
'ccList' => $this->getCCList(true),
];
}

/**
Expand All @@ -516,7 +525,7 @@ public function getPlainBody() {
}

/**
* @param \Horde_Mime_Part $part
* @param Horde_Mime_Part $part
* @param int $partNo
*/
private function handleMultiPartMessage($part, $partNo) {
Expand All @@ -528,7 +537,7 @@ private function handleMultiPartMessage($part, $partNo) {
}

/**
* @param \Horde_Mime_Part $p
* @param Horde_Mime_Part $p
* @param int $partNo
*/
private function handleTextMessage($p, $partNo) {
Expand All @@ -538,7 +547,7 @@ private function handleTextMessage($p, $partNo) {
}

/**
* @param \Horde_Mime_Part $p
* @param Horde_Mime_Part $p
* @param int $partNo
*/
private function handleHtmlMessage($p, $partNo) {
Expand All @@ -550,16 +559,16 @@ private function handleHtmlMessage($p, $partNo) {
}

/**
* @param \Horde_Mime_Part $p
* @param Horde_Mime_Part $p
* @param int $partNo
* @return string
* @throws DoesNotExistException
* @throws \Exception
*/
private function loadBodyData($p, $partNo) {
// DECODE DATA
$fetch_query = new \Horde_Imap_Client_Fetch_Query();
$ids = new \Horde_Imap_Client_Ids($this->messageId);
$fetch_query = new Horde_Imap_Client_Fetch_Query();
$ids = new Horde_Imap_Client_Ids($this->messageId);

$fetch_query->bodyPart($partNo, [
'peek' => true
Expand Down
9 changes: 2 additions & 7 deletions lib/service/iaccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,16 @@
*/
namespace OCA\Mail\Service;

use JsonSerializable;
use OCA\Mail\Model\IMessage;

interface IAccount {
interface IAccount extends JsonSerializable {

/**
* @return array
*/
public function getConfiguration();

/**
* @return array
* TODO: function name is :hankey:
*/
public function getListArray();

/**
* @param $folderId
* @return IMailbox
Expand Down
3 changes: 2 additions & 1 deletion lib/service/imailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/
namespace OCA\Mail\Service;

use Horde_Imap_Client_Search_Query;
use OCA\Mail\Attachment;
use OCA\Mail\Message;

Expand All @@ -34,7 +35,7 @@ public function getFolderId();
/**
* @param int $from
* @param int $count
* @param string|\Horde_Imap_Client_Search_Query $filter
* @param string|Horde_Imap_Client_Search_Query $filter
* @return array
*/
public function getMessages($from, $count, $filter);
Expand Down
Loading