summaryrefslogtreecommitdiff
path: root/lib/kolab_sync_data_email.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-08-22 12:55:08 (GMT)
committerAleksander Machniak <alec@alec.pl>2012-08-22 12:55:08 (GMT)
commitc5ce4e2dc08661a062b31318b145487e32808175 (patch)
tree4c4c0d535ef65d855b20df678978a14fd75fe157 /lib/kolab_sync_data_email.php
parent0f607ae7b4305b376223acb133305f270c1bce5f (diff)
downloadkolab-syncroton-c5ce4e2dc08661a062b31318b145487e32808175.tar.gz
Small improvements in email backend, added lost PEAR packages
Diffstat (limited to 'lib/kolab_sync_data_email.php')
-rw-r--r--lib/kolab_sync_data_email.php127
1 files changed, 68 insertions, 59 deletions
diff --git a/lib/kolab_sync_data_email.php b/lib/kolab_sync_data_email.php
index f8b7df8..311ef70 100644
--- a/lib/kolab_sync_data_email.php
+++ b/lib/kolab_sync_data_email.php
@@ -188,31 +188,14 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
$opts = $collection->options;
$prefs = $opts['bodyPreferences'];
- if ($opts['mimeSupport'] == 2 && ($this->asversion <= 12 || !empty($prefs[4]))) {
- if (!empty($prefs[4]) && !empty($prefs[4]['truncationSize'])) {
- $truncateAt = $prefs[4]['truncationSize'];
- }
- $airSyncBaseType = 4;
- }
- else if (!empty($prefs[2])) {
- if (!empty($prefs[2]['truncationSize'])) {
- $truncateAt = $prefs[2]['truncationSize'];
- }
- $airSyncBaseType = 2;
- }
- else {
- // @TODO: In Sync examples there's one in which bodyPreferences is not defined
- // in such case Truncated=1 and there's no body sent to the client
- // only it's estimated size
+ if ($opts['mimeSupport'] == Syncroton_Command_Sync::MIMESUPPORT_SEND_MIME) {
+ $airSyncBaseType = Syncroton_Command_Sync::BODY_TYPE_MIME;
- if (!empty($prefs[1]) && !empty($prefs[1]['truncationSize'])) {
- $truncateAt = $prefs[1]['truncationSize'];
+ if (isset($prefs[Syncroton_Command_Sync::BODY_TYPE_MIME]['truncationSize'])) {
+ $truncateAt = $prefs[Syncroton_Command_Sync::BODY_TYPE_MIME]['truncationSize'];
}
- $airSyncBaseType = 1;
- }
-
- if (isset($opts['mimeTruncation']) && $opts['mimeTruncation'] < 8) {
- switch ($opts['mimeTruncation']) {
+ else if (isset($opts['mimeTruncation']) && $opts['mimeTruncation'] < Syncroton_Command_Sync::TRUNCATE_NOTHING) {
+ switch ($opts['mimeTruncation']) {
case Syncroton_Command_Sync::TRUNCATE_ALL:
$truncateAt = 0;
break;
@@ -237,47 +220,69 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
case Syncroton_Command_Sync::TRUNCATE_102400:
$truncateAt = 102400;
break;
+ }
+ }
+ }
+ else if (!empty($prefs[Syncroton_Command_Sync::BODY_TYPE_HTML])) {
+ if (!empty($prefs[Syncroton_Command_Sync::BODY_TYPE_HTML]['truncationSize'])) {
+ $truncateAt = $prefs[Syncroton_Command_Sync::BODY_TYPE_HTML]['truncationSize'];
+ }
+ $airSyncBaseType = Syncroton_Command_Sync::BODY_TYPE_HTML;
+ }
+ else {
+ if (!empty($prefs[Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT]) && !empty($prefs[Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT]['truncationSize'])) {
+ $truncateAt = $prefs[Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT]['truncationSize'];
}
+ $airSyncBaseType = Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT;
}
// Message body
- if ($airSyncBaseType == 4) {
+ // In Sync examples there's one in which bodyPreferences is not defined
+ // in such case Truncated=1 and there's no body sent to the client
+ // only it's estimated size
+ if (empty($prefs)) {
+ $messageBody = '';
+ $real_length = $message->size;
+ $truncateAt = 0;
+ $body_length = 0;
+ }
+ else if ($airSyncBaseType == 4) {
$messageBody = $this->storage->get_raw_body($message->uid);
+ // strip out any non utf-8 characters
+ $messageBody = rcube_charset::clean($messageBody);
+ $real_length = $body_length = strlen($messageBody);
}
else {
- $messageBody = $this->getMessageBody($message, $airSyncBaseType == 2);
+ $messageBody = $this->getMessageBody($message, $airSyncBaseType == Syncroton_Command_Sync::BODY_TYPE_HTML);
+ // strip out any non utf-8 characters
+ $messageBody = rcube_charset::clean($messageBody);
+ $real_length = $body_length = strlen($messageBody);
}
- // strip out any non utf-8 characters
- $messageBody = rcube_charset::clean($messageBody);
-
- $real_length = $body_length = strlen($messageBody);
-
- if ($truncateAt !== null && $body_length > $truncateAt) {
- $messageBody = substr($messageBody, 0, $truncateAt);
- $body_length = $truncateAt;
+ if ($truncateAt !== null) {
+ if ($body_length > $truncateAt) {
+ $messageBody = substr($messageBody, 0, $truncateAt);
+ $body_length = $truncateAt;
+ }
$isTruncacted = 1;
}
else {
$isTruncacted = 0;
}
- if ($body_length > 0) {
- $body_params = array(
- 'Type' => $airSyncBaseType,
- 'Truncated' => $isTruncacted,
- );
- if ($isTruncated) {
- $body_params['EstimatedDataSize'] = $real_length;
- }
-
- $result['Body'] = $this->setBody($messageBody, $body_params);
+ $body_params = array(
+ 'Type' => $airSyncBaseType,
+ 'Truncated' => $isTruncacted,
+ );
+ if ($isTruncated) {
+ $body_params['EstimatedDataSize'] = $real_length;
}
+ $result['Body'] = $this->setBody($messageBody, $body_params);
$result['NativeBodyType'] = intval($message->has_html_part(false));
// Message class
- $result['MessageClass'] = 'IPM.Note' . ($airSyncBaseType == 4 ? '.SMIME' : '');
+ $result['MessageClass'] = 'IPM.Note' . ($airSyncBaseType == Syncroton_Command_Sync::MIMESUPPORT_SEND_MIME ? '.SMIME' : '');
$result['ContentClass'] = 'urn:content-classes:message';
// attachments
@@ -527,16 +532,18 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
list($headers, $body) = $this->backend->parse_mime($body, true);
// Get original message body
- // @TODO: here we're assuming that reply message is in text/plain format
- // So, original message will be converted to plain text if needed
- // @TODO: what about forward-as-attachment?
- $message_body = $this->getMessageBody($message, false);
- $message_body = trim($message_body);
+ if (!$replaceMime) {
+ // @TODO: here we're assuming that reply message is in text/plain format
+ // So, original message will be converted to plain text if needed
+ // @TODO: what about forward-as-attachment?
+ $message_body = $this->getMessageBody($message, false);
+ $message_body = trim($message_body);
- // Join bodies
- $body = rtrim($body) . "\n\n" . ltrim($message_body);
+ // Join bodies
+ $body = rtrim($body) . "\n\n" . ltrim($message_body);
- // @TODO: add attachments from the original message
+ // @TODO: add attachments from the original message
+ }
// Create complete message source
$body = $this->backend->build_mime($headers, $body);
@@ -565,15 +572,17 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
list($headers, $body) = $this->backend->parse_mime($body, true);
// Get original message body
- // @TODO: here we're assuming that reply message is in text/plain format
- // So, original message will be converted to plain text if needed
- $message_body = $this->getMessageBody($message, false);
+ if (!$replaceMime) {
+ // @TODO: here we're assuming that reply message is in text/plain format
+ // So, original message will be converted to plain text if needed
+ $message_body = $this->getMessageBody($message, false);
- // Quote original message body
- $message_body = self::wrap_and_quote(trim($message_body), 72);
+ // Quote original message body
+ $message_body = self::wrap_and_quote(trim($message_body), 72);
- // Join bodies
- $body = rtrim($body) . "\n" . ltrim($message_body);
+ // Join bodies
+ $body = rtrim($body) . "\n" . ltrim($message_body);
+ }
// Create complete message source
$body = $this->backend->build_mime($headers, $body);