summaryrefslogtreecommitdiff
path: root/lib/kolab_sync_data_email.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-08-30 09:01:48 (GMT)
committerAleksander Machniak <alec@alec.pl>2012-08-30 09:01:48 (GMT)
commit71cc2c50f97fa886a0423e8cd036813ee837f232 (patch)
treeea8ba78da45963f4bb318dd124fab7fe7222fb73 /lib/kolab_sync_data_email.php
parent123f9895a5ef31d255e624422f4514dfe85fb491 (diff)
downloadkolab-syncroton-71cc2c50f97fa886a0423e8cd036813ee837f232.tar.gz
Throw exception when email sending fails
Diffstat (limited to 'lib/kolab_sync_data_email.php')
-rw-r--r--lib/kolab_sync_data_email.php90
1 files changed, 54 insertions, 36 deletions
diff --git a/lib/kolab_sync_data_email.php b/lib/kolab_sync_data_email.php
index 6b6778d..eb63e9d 100644
--- a/lib/kolab_sync_data_email.php
+++ b/lib/kolab_sync_data_email.php
@@ -387,7 +387,6 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
return $filter;
}
-
/**
* Returns default folder for current class type.
*/
@@ -406,7 +405,15 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
);
}
-
+ /**
+ * Moves object into another location (folder)
+ *
+ * @param string $srcFolderId Source folder identifier
+ * @param string $serverId Object identifier
+ * @param string $dstFolderId Destination folder identifier
+ *
+ * @return string New object identifier
+ */
public function moveItem($srcFolderId, $serverId, $dstFolderId)
{
$msg = $this->parseMessageId($serverId);
@@ -500,15 +507,43 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
}
}
+ /**
+ * Send an email
+ *
+ * @param resource|string $body MIME message
+ * @param boolean $saveInSent Enables saving the sent message in Sent folder
+ *
+ * @param throws Syncroton_Exception_Status
+ */
public function sendEmail($body, $saveInSent)
{
$sent = $this->backend->send_message($body, $smtp_error);
- if ($sent && $saveInSent) {
- $this->saveInSent($body);
+ if (!$sent) {
+ throw Syncroton_Exception_Status(Syncroton_Exception_Status::MAIL_SUBMISSION_FAILED);
+ }
+
+ // Save sent message in Sent folder
+ if ($saveInSent) {
+ $sent_folder = kolab_sync::get_instance()->config->get('sent_mbox');
+
+ if (strlen($sent_folder) && $this->storage->folder_exists($sent_folder)) {
+ return $this->storage->save_message($sent_folder, $body);
+ }
}
}
+ /**
+ * Forward an email
+ *
+ * @param array|string $itemId A string LongId or an array with following properties:
+ * collectionId, itemId and instanceId
+ * @param resource|string $body MIME message
+ * @param boolean $saveInSent Enables saving the sent message in Sent folder
+ * @param boolean $replaceMime If enabled, original message would be appended
+ *
+ * @param throws Syncroton_Exception_Status
+ */
public function forwardEmail($itemId, $body, $saveInSent, $replaceMime)
{
/*
@@ -548,19 +583,25 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
$body = $this->backend->build_mime($headers, $body);
// Send message
- $sent = $this->backend->send_message($body, $smtp_error);
+ $sent = $this->sendEmail($body, $saveInSent);
// Set FORWARDED flag on the replied message
- if ($sent && empty($message->headers->flags['FORWARDED'])) {
+ if (empty($message->headers->flags['FORWARDED'])) {
$this->storage->set_flag($msg['uid'], 'FORWARDED', $msg['foldername']);
}
-
- // Save sent message in Sent folder
- if ($sent && $saveInSent) {
- $this->saveInSent($body);
- }
}
+ /**
+ * Reply to an email
+ *
+ * @param array|string $itemId A string LongId or an array with following properties:
+ * collectionId, itemId and instanceId
+ * @param resource|string $body MIME message
+ * @param boolean $saveInSent Enables saving the sent message in Sent folder
+ * @param boolean $replaceMime If enabled, original message would be appended
+ *
+ * @param throws Syncroton_Exception_Status
+ */
public function replyEmail($itemId, $body, $saveInSent, $replaceMime)
{
$msg = $this->parseMessageId($itemId);
@@ -587,35 +628,12 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
$body = $this->backend->build_mime($headers, $body);
// Send message
- $sent = $this->backend->send_message($body, $smtp_error);
+ $sent = $this->sendEmail($body, $saveInSent);
// Set ANSWERED flag on the replied message
- if ($sent && empty($message->headers->flags['ANSWERED'])) {
+ if (empty($message->headers->flags['ANSWERED'])) {
$this->storage->set_flag($msg['uid'], 'ANSWERED', $msg['foldername']);
}
-
- // Save sent message in Sent folder
- if ($sent && $saveInSent) {
- $this->saveInSent($body);
- }
- }
-
- /**
- * Append the message into Sent folder
- *
- * @param string $message Complete message source
- *
- * @return int|bool Appended message UID or True on success, False on error
- */
- protected function saveInSent($message)
- {
- $sent_folder = kolab_sync::get_instance()->config->get('sent_mbox');
-
- if (strlen($sent_folder) && $this->storage->folder_exists($sent_folder)) {
- return $this->storage->save_message($sent_folder, $message);
- }
-
- return false;
}
/**