Index: trunk/zpush/backend/expresso/providers/imapProvider.php
===================================================================
--- trunk/zpush/backend/expresso/providers/imapProvider.php	(revision 7644)
+++ trunk/zpush/backend/expresso/providers/imapProvider.php	(revision 7671)
@@ -1,46 +1,46 @@
 <?php
 /***********************************************
- * File      :   imap.php
- * Project   :   Z-Push
- * Descr     :   This backend is based on
- *               'BackendDiff' and implements an
- *               IMAP interface
- *
- * Created   :   10.10.2007
- *
- * Copyright 2007 - 2012 Zarafa Deutschland GmbH
- *
- * This program 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 with the following additional
- * term according to sec. 7:
- *
- * According to sec. 7 of the GNU Affero General Public License, version 3,
- * the terms of the AGPL are supplemented with the following terms:
- *
- * "Zarafa" is a registered trademark of Zarafa B.V.
- * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
- * The licensing of the Program under the AGPL does not imply a trademark license.
- * Therefore any rights, title and interest in our trademarks remain entirely with us.
- *
- * However, if you propagate an unmodified version of the Program you are
- * allowed to use the term "Z-Push" to indicate that you distribute the Program.
- * Furthermore you may use our trademarks where it is necessary to indicate
- * the intended purpose of a product or service provided you use it in accordance
- * with honest practices in industrial or commercial matters.
- * If you want to propagate modified versions of the Program under the name "Z-Push",
- * you may only do so if you have a written permission by Zarafa Deutschland GmbH
- * (to acquire a permission please contact Zarafa at trademark@zarafa.com).
- *
- * 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
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- * Consult LICENSE file for details
- ************************************************/
+* File      :   imap.php
+* Project   :   Z-Push
+* Descr     :   This backend is based on
+*               'BackendDiff' and implements an
+*               IMAP interface
+*
+* Created   :   10.10.2007
+*
+* Copyright 2007 - 2012 Zarafa Deutschland GmbH
+*
+* This program 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 with the following additional
+* term according to sec. 7:
+*
+* According to sec. 7 of the GNU Affero General Public License, version 3,
+* the terms of the AGPL are supplemented with the following terms:
+*
+* "Zarafa" is a registered trademark of Zarafa B.V.
+* "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
+* The licensing of the Program under the AGPL does not imply a trademark license.
+* Therefore any rights, title and interest in our trademarks remain entirely with us.
+*
+* However, if you propagate an unmodified version of the Program you are
+* allowed to use the term "Z-Push" to indicate that you distribute the Program.
+* Furthermore you may use our trademarks where it is necessary to indicate
+* the intended purpose of a product or service provided you use it in accordance
+* with honest practices in industrial or commercial matters.
+* If you want to propagate modified versions of the Program under the name "Z-Push",
+* you may only do so if you have a written permission by Zarafa Deutschland GmbH
+* (to acquire a permission please contact Zarafa at trademark@zarafa.com).
+*
+* 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
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*
+* Consult LICENSE file for details
+************************************************/
 
 include_once(__DIR__.'/../../../lib/default/diffbackend/diffbackend.php');
@@ -60,4 +60,5 @@
     protected $sinkfolders;
     protected $sinkstates;
+    protected $excludedFolders; /* fmbiete's contribution r1527, ZP-319 */
 
     /**----------------------------------------------------------------------------------------------------------
@@ -82,5 +83,13 @@
 
         if (!function_exists("imap_open"))
-            throw new FatalException("ExpressoImapProvider(): php-imap module is not installed", 0, null, LOGLEVEL_FATAL);
+            throw new FatalException("BackendIMAP(): php-imap module is not installed", 0, null, LOGLEVEL_FATAL);
+
+        /* BEGIN fmbiete's contribution r1527, ZP-319 */
+        $this->excludedFolders = array();
+        if (defined('IMAP_EXCLUDED_FOLDERS')) {
+            $this->excludedFolders = explode("|", IMAP_EXCLUDED_FOLDERS);
+            ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->Logon(): Excluding Folders (%s)", IMAP_EXCLUDED_FOLDERS));
+        }
+        /* END fmbiete's contribution r1527, ZP-319 */
 
         // open the IMAP-mailbox
@@ -115,5 +124,5 @@
 
         if ($this->mbox) {
-            ZLog::Write(LOGLEVEL_INFO, sprintf("ExpressoImapProvider->Logon(): User '%s' is authenticated on IMAP",$username));
+            ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->Logon(): User '%s' is authenticated on IMAP",$username));
             $this->username = $username;
             $this->domain = $domain;
@@ -123,5 +132,5 @@
         }
         else {
-            ZLog::Write(LOGLEVEL_ERROR, "ExpressoImapProvider->Logon(): can't connect: " . imap_last_error());
+            ZLog::Write(LOGLEVEL_ERROR, "BackendIMAP->Logon(): can't connect: " . imap_last_error());
             return false;
         }
@@ -141,14 +150,16 @@
             $errors = imap_errors();
             if (is_array($errors)) {
-                foreach ($errors as $e)
-                    if (stripos($e, "fail") !== false)
+                foreach ($errors as $e) {
+                    if (stripos($e, "fail") !== false) {
                         $level = LOGLEVEL_WARN;
-                    else
+                    }
+                    else {
                         $level = LOGLEVEL_DEBUG;
-
-                ZLog::Write($level, "ExpressoImapProvider->Logoff(): IMAP said: " . $e);
+                    }
+                    ZLog::Write($level, "BackendIMAP->Logoff(): IMAP said: " . $e);
+                }
             }
             @imap_close($this->mbox);
-            ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->Logoff(): IMAP connection closed");
+            ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->Logoff(): IMAP connection closed");
         }
         $this->SaveStorages();
@@ -171,7 +182,7 @@
 
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("IMAPBackend->SendMail(): RFC822: %d bytes  forward-id: '%s' reply-id: '%s' parent-id: '%s' SaveInSent: '%s' ReplaceMIME: '%s'",
-            strlen($sm->mime), Utils::PrintAsString($sm->forwardflag), Utils::PrintAsString($sm->replyflag),
-            Utils::PrintAsString((isset($sm->source->folderid) ? $sm->source->folderid : false)),
-            Utils::PrintAsString(($sm->saveinsent)), Utils::PrintAsString(isset($sm->replacemime)) ));
+                                            strlen($sm->mime), Utils::PrintAsString($sm->forwardflag), Utils::PrintAsString($sm->replyflag),
+                                            Utils::PrintAsString((isset($sm->source->folderid) ? $sm->source->folderid : false)),
+                                            Utils::PrintAsString(($sm->saveinsent)), Utils::PrintAsString(isset($sm->replacemime)) ));
 
         if (isset($sm->source->folderid) && $sm->source->folderid)
@@ -307,5 +318,5 @@
             $origmail = @imap_fetchheader($this->mbox, $reply, FT_UID) . @imap_body($this->mbox, $reply, FT_PEEK | FT_UID);
             if (!$origmail)
-                throw new StatusException(sprintf("ExpressoImapProvider->SendMail(): Could not open message id '%s' in folder id '%s' to be replied: %s", $reply, $parent, imap_last_error()), SYNC_COMMONSTATUS_ITEMNOTFOUND);
+                throw new StatusException(sprintf("BackendIMAP->SendMail(): Could not open message id '%s' in folder id '%s' to be replied: %s", $reply, $parent, imap_last_error()), SYNC_COMMONSTATUS_ITEMNOTFOUND);
 
             $mobj2 = new Mail_mimeDecode($origmail);
@@ -329,5 +340,5 @@
 
             if (!$origmail)
-                throw new StatusException(sprintf("ExpressoImapProvider->SendMail(): Could not open message id '%s' in folder id '%s' to be forwarded: %s", $forward, $parent, imap_last_error()), SYNC_COMMONSTATUS_ITEMNOTFOUND);
+                throw new StatusException(sprintf("BackendIMAP->SendMail(): Could not open message id '%s' in folder id '%s' to be forwarded: %s", $forward, $parent, imap_last_error()), SYNC_COMMONSTATUS_ITEMNOTFOUND);
 
             if (!defined('IMAP_INLINE_FORWARD') || IMAP_INLINE_FORWARD === false) {
@@ -370,11 +381,11 @@
                     $nbody = chunk_split(base64_encode($nbody));
                     if ($use_orgbody)
-                        // contrib - chunk base64 encoded body
+                    // contrib - chunk base64 encoded body
                         $repl_body = chunk_split(base64_encode($repl_body));
                 }
 
                 if ($use_orgbody) {
-                    ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): -------------------");
-                    ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): old:\n'$repl_body'\nnew:\n'$nbody'\nund der body:\n'$body'");
+                    ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): -------------------");
+                    ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): old:\n'$repl_body'\nnew:\n'$nbody'\nund der body:\n'$body'");
                     //$body is quoted-printable encoded while $repl_body and $nbody are plain text,
                     //so we need to decode $body in order replace to take place
@@ -434,10 +445,10 @@
                         //2. multipart/alternative part which is the original message
                         $body = "This is a message with multiple parts in MIME format.\n--".
-                            $att_boundary.
-                            "\nContent-Type: $forward_h_ct\nContent-Transfer-Encoding: $forward_h_cte\n\n".
-                            (($body_base64) ? chunk_split(base64_encode($message->body)) : rtrim($message->body)).
-                            "\n--".$att_boundary.
-                            "\nContent-Type: {$mess2->headers['content-type']}\n\n".
-                            @imap_body($this->mbox, $forward, FT_PEEK | FT_UID)."\n\n";
+                                $att_boundary.
+                                "\nContent-Type: $forward_h_ct\nContent-Transfer-Encoding: $forward_h_cte\n\n".
+                                (($body_base64) ? chunk_split(base64_encode($message->body)) : rtrim($message->body)).
+                                "\n--".$att_boundary.
+                                "\nContent-Type: {$mess2->headers['content-type']}\n\n".
+                                @imap_body($this->mbox, $forward, FT_PEEK | FT_UID)."\n\n";
                     }
                     $body .= "--$att_boundary--\n\n";
@@ -458,5 +469,5 @@
             if (!empty($forward_h_ct)) $headers .= "\nContent-Type: $forward_h_ct";
             if (!empty($forward_h_cte)) $headers .= "\nContent-Transfer-Encoding: $forward_h_cte";
-            //  if body was quoted-printable, convert it again
+        //  if body was quoted-printable, convert it again
             if (isset($message->headers["content-transfer-encoding"]) && strtolower($message->headers["content-transfer-encoding"]) == "quoted-printable") {
                 $body = quoted_printable_encode($body);
@@ -465,10 +476,19 @@
 
         // more debugging
-        ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): parsed message: ". print_r($message,1));
-        ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): headers: $headers");
-        ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): subject: {$message->headers["subject"]}");
-        ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): body: $body");
+        ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): parsed message: ". print_r($message,1));
+        ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): headers: $headers");
+        /* BEGIN fmbiete's contribution r1528, ZP-320 */
+        if (isset($message->headers["subject"])) {
+            ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): subject: {$message->headers["subject"]}");
+        }
+        else {
+            ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): subject: no subject set. Set to empty.");
+            $message->headers["subject"] = ""; // added by mku ZP-330
+        }
+        /* END fmbiete's contribution r1528, ZP-320 */
+        ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): body: $body");
 
         if (!defined('IMAP_USE_IMAPMAIL') || IMAP_USE_IMAPMAIL == true) {
+            // changed by mku ZP-330
             $send =  @imap_mail ( $toaddr, $message->headers["subject"], $body, $headers, $ccaddr, $bccaddr);
         }
@@ -476,4 +496,5 @@
             if (!empty($ccaddr))  $headers .= "\nCc: $ccaddr";
             if (!empty($bccaddr)) $headers .= "\nBcc: $bccaddr";
+            // changed by mku ZP-330
             $send =  @mail ( $toaddr, $message->headers["subject"], $body, $headers, $envelopefrom );
         }
@@ -481,10 +502,10 @@
         // email sent?
         if (!$send)
-            throw new StatusException(sprintf("ExpressoImapProvider->SendMail(): The email could not be sent. Last IMAP-error: %s", imap_last_error()), SYNC_COMMONSTATUS_MAILSUBMISSIONFAILED);
+            throw new StatusException(sprintf("BackendIMAP->SendMail(): The email could not be sent. Last IMAP-error: %s", imap_last_error()), SYNC_COMMONSTATUS_MAILSUBMISSIONFAILED);
 
         // add message to the sent folder
         // build complete headers
         $headers .= "\nTo: $toaddr";
-        $headers .= "\nSubject: " . $message->headers["subject"];
+        $headers .= "\nSubject: " . $message->headers["subject"]; // changed by mku ZP-330
 
         if (!defined('IMAP_USE_IMAPMAIL') || IMAP_USE_IMAPMAIL == true) {
@@ -492,5 +513,5 @@
             if (!empty($bccaddr)) $headers .= "\nBcc: $bccaddr";
         }
-        ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): complete headers: $headers");
+        ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): complete headers: $headers");
 
         $asf = false;
@@ -500,19 +521,19 @@
         else if (IMAP_SENTFOLDER) {
             $asf = $this->addSentMessage(IMAP_SENTFOLDER, $headers, $body);
-            ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->SendMail(): Outgoing mail saved in configured 'Sent' folder '%s': %s", IMAP_SENTFOLDER, Utils::PrintAsString($asf)));
+            ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->SendMail(): Outgoing mail saved in configured 'Sent' folder '%s': %s", IMAP_SENTFOLDER, Utils::PrintAsString($asf)));
         }
         // No Sent folder set, try defaults
         else {
-            ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): No Sent mailbox set");
+            ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): No Sent mailbox set");
             if($this->addSentMessage("INBOX.Sent", $headers, $body)) {
-                ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): Outgoing mail saved in 'INBOX.Sent'");
+                ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): Outgoing mail saved in 'INBOX.Sent'");
                 $asf = true;
             }
             else if ($this->addSentMessage("Sent", $headers, $body)) {
-                ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): Outgoing mail saved in 'Sent'");
+                ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): Outgoing mail saved in 'Sent'");
                 $asf = true;
             }
             else if ($this->addSentMessage("Sent Items", $headers, $body)) {
-                ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail():IMAP-SendMail: Outgoing mail saved in 'Sent Items'");
+                ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail():IMAP-SendMail: Outgoing mail saved in 'Sent Items'");
                 $asf = true;
             }
@@ -520,5 +541,5 @@
 
         if (!$asf) {
-            ZLog::Write(LOGLEVEL_ERROR, "ExpressoImapProvider->SendMail(): The email could not be saved to Sent Items folder. Check your configuration.");
+            ZLog::Write(LOGLEVEL_ERROR, "BackendIMAP->SendMail(): The email could not be saved to Sent Items folder. Check your configuration.");
         }
 
@@ -560,10 +581,10 @@
      */
     public function GetAttachmentData($attname) {
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->GetAttachmentData('%s')", $attname));
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetAttachmentData('%s')", $attname));
 
         list($folderid, $id, $part) = explode(":", $attname);
 
         if (!$folderid || !$id || !$part)
-            throw new StatusException(sprintf("ExpressoImapProvider->GetAttachmentData('%s'): Error, attachment name key can not be parsed", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
+            throw new StatusException(sprintf("BackendIMAP->GetAttachmentData('%s'): Error, attachment name key can not be parsed", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
 
         // convert back to work on an imap-id
@@ -576,6 +597,19 @@
         $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
 
-        if (!isset($message->parts[$part]->body))
-            throw new StatusException(sprintf("ExpressoImapProvider->GetAttachmentData('%s'): Error, requested part key can not be found: '%d'", $attname, $part), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
+        /* BEGIN fmbiete's contribution r1528, ZP-320 */
+        //trying parts
+        $mparts = $message->parts;
+        for ($i = 0; $i < count($mparts); $i++) {
+            $auxpart = $mparts[$i];
+            //recursively add parts
+            if($auxpart->ctype_primary == "multipart" && ($auxpart->ctype_secondary == "mixed" || $auxpart->ctype_secondary == "alternative"  || $auxpart->ctype_secondary == "related")) {
+                foreach($auxpart->parts as $spart)
+                    $mparts[] = $spart;
+            }
+        }
+        /* END fmbiete's contribution r1528, ZP-320 */
+
+        if (!isset($mparts[$part]->body))
+            throw new StatusException(sprintf("BackendIMAP->GetAttachmentData('%s'): Error, requested part key can not be found: '%d'", $attname, $part), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
 
         // unset mimedecoder & mail
@@ -585,7 +619,14 @@
         include_once('include/stringstreamwrapper.php');
         $attachment = new SyncItemOperationsAttachment();
-        $attachment->data = StringStreamWrapper::Open($message->parts[$part]->body);
-        if (isset($message->parts[$part]->ctype_primary) && isset($message->parts[$part]->ctype_secondary))
-            $attachment->contenttype = $message->parts[$part]->ctype_primary .'/'.$message->parts[$part]->ctype_secondary;
+        /* BEGIN fmbiete's contribution r1528, ZP-320 */
+        $attachment->data = StringStreamWrapper::Open($mparts[$part]->body);
+        if (isset($mparts[$part]->ctype_primary) && isset($mparts[$part]->ctype_secondary))
+            $attachment->contenttype = $mparts[$part]->ctype_primary .'/'.$mparts[$part]->ctype_secondary;
+
+        unset($mparts);
+        unset($message);
+
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetAttachmentData contenttype %s", $attachment->contenttype));
+        /* END fmbiete's contribution r1528, ZP-320 */
 
         return $attachment;
@@ -690,5 +731,5 @@
         $folders = array();
 
-        $list = @imap_getmailboxes($this->mbox, $this->server, "INBOX*");
+        $list = @imap_getmailboxes($this->mbox, $this->server, "*");
         if (is_array($list)) {
             // reverse list to obtain folders in right order
@@ -696,23 +737,37 @@
 
             foreach ($list as $val) {
-                $box = array();
-                // cut off serverstring
-                $imapid = substr($val->name, strlen($this->server));
-                $box["id"] = $this->convertImapId($imapid);
-
-                $fhir = explode($val->delimiter, $imapid);
-                if (count($fhir) > 1) {
-                    $this->getModAndParentNames($fhir, $box["mod"], $imapparent);
-                    $box["parent"] = $this->convertImapId($imapparent);
-                }
-                else {
-                    $box["mod"] = $imapid;
-                    $box["parent"] = "0";
-                }
-                $folders[]=$box;
+                /* BEGIN fmbiete's contribution r1527, ZP-319 */
+                // don't return the excluded folders
+                $notExcluded = true;
+                for ($i = 0, $cnt = count($this->excludedFolders); $notExcluded && $i < $cnt; $i++) { // expr1, expr2 modified by mku ZP-329
+                    // fix exclude folders with special chars by mku ZP-329
+                    if (strpos(strtolower($val->name), strtolower(Utils::Utf7_iconv_encode(Utils::Utf8_to_utf7($this->excludedFolders[$i])))) !== false) {
+                        $notExcluded = false;
+                        ZLog::Write(LOGLEVEL_DEBUG, sprintf("Pattern: <%s> found, excluding folder: '%s'", $this->excludedFolders[$i], $val->name)); // sprintf added by mku ZP-329
+                    }
+                }
+
+                if ($notExcluded) {
+                    $box = array();
+                    // cut off serverstring
+                    $imapid = substr($val->name, strlen($this->server));
+                    $box["id"] = $this->convertImapId($imapid);
+
+                    $fhir = explode($val->delimiter, $imapid);
+                    if (count($fhir) > 1) {
+                        $this->getModAndParentNames($fhir, $box["mod"], $imapparent);
+                        $box["parent"] = $this->convertImapId($imapparent);
+                    }
+                    else {
+                        $box["mod"] = $imapid;
+                        $box["parent"] = "0";
+                    }
+                    $folders[]=$box;
+                    /* END fmbiete's contribution r1527, ZP-319 */
+                }
             }
         }
         else {
-            ZLog::Write(LOGLEVEL_WARN, "ExpressoImapProvider->GetFolderList(): imap_list failed: " . imap_last_error());
+            ZLog::Write(LOGLEVEL_WARN, "BackendIMAP->GetFolderList(): imap_list failed: " . imap_last_error());
             return false;
         }
@@ -795,9 +850,9 @@
                 $folder->parentid = "0";
             }
-            $folder->type = SYNC_FOLDER_TYPE_OTHER;
+            $folder->type = SYNC_FOLDER_TYPE_USER_MAIL;
         }
 
         //advanced debugging
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->GetFolder('%s'): '%s'", $id, $folder));
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetFolder('%s'): '%s'", $id, $folder));
 
         return $folder;
@@ -838,5 +893,5 @@
      */
     public function ChangeFolder($folderid, $oldid, $displayname, $type){
-        ZLog::Write(LOGLEVEL_INFO, sprintf("ExpressoImapProvider->ChangeFolder('%s','%s','%s','%s')", $folderid, $oldid, $displayname, $type));
+        ZLog::Write(LOGLEVEL_INFO, sprintf("BackendIMAP->ChangeFolder('%s','%s','%s','%s')", $folderid, $oldid, $displayname, $type));
 
         // go to parent mailbox
@@ -891,5 +946,5 @@
      */
     public function GetMessageList($folderid, $cutoffdate) {
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->GetMessageList('%s','%s')", $folderid, $cutoffdate));
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessageList('%s','%s')", $folderid, $cutoffdate));
 
         $folderid = $this->getImapIdFromFolderId($folderid);
@@ -907,9 +962,9 @@
                 $sequence = implode(",", $search);
         }
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->GetMessageList(): searching with sequence '%s'", $sequence));
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessageList(): searching with sequence '%s'", $sequence));
         $overviews = @imap_fetch_overview($this->mbox, $sequence);
 
         if (!$overviews || !is_array($overviews)) {
-            ZLog::Write(LOGLEVEL_WARN, sprintf("ExpressoImapProvider->GetMessageList('%s','%s'): Failed to retrieve overview: %s",$folderid, $cutoffdate, imap_last_error()));
+            ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->GetMessageList('%s','%s'): Failed to retrieve overview: %s",$folderid, $cutoffdate, imap_last_error()));
             return $messages;
         }
@@ -925,8 +980,8 @@
 
             // cut of deleted messages
-            if (array_key_exists( "deleted", $vars) && $overview->deleted)
+            if (array_key_exists("deleted", $vars) && $overview->deleted)
                 continue;
 
-            if (array_key_exists( "uid", $vars)) {
+            if (array_key_exists("uid", $vars)) {
                 $message = array();
                 $message["mod"] = $date;
@@ -957,5 +1012,6 @@
         $truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
         $mimesupport = $contentparameters->GetMimeSupport();
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->GetMessage('%s','%s')", $folderid,  $id));
+        $bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage('%s','%s')", $folderid,  $id));
 
         $folderImapid = $this->getImapIdFromFolderId($folderid);
@@ -971,19 +1027,96 @@
             $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
 
+            /* BEGIN fmbiete's contribution r1528, ZP-320 */
             $output = new SyncMail();
 
-            $body = $this->getBody($message);
-            $output->bodysize = strlen($body);
-
-            // truncate body, if requested
-            if(strlen($body) > $truncsize) {
-                $body = Utils::Utf8_truncate($body, $truncsize);
-                $output->bodytruncated = 1;
-            } else {
-                $body = $body;
+            //Select body type preference
+            $bpReturnType = SYNC_BODYPREFERENCE_PLAIN;
+            if ($bodypreference !== false) {
+                $bpReturnType = Utils::GetBodyPreferenceBestMatch($bodypreference); // changed by mku ZP-330
+            }
+            ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage - getBodyPreferenceBestMatch: %d", $bpReturnType));
+
+            //Get body data
+            $this->getBodyRecursive($message, "plain", $plainBody);
+            $this->getBodyRecursive($message, "html", $htmlBody);
+            if ($plainBody == "") {
+                $plainBody = Utils::ConvertHtmlToText($htmlBody);
+            }
+            $htmlBody = str_replace("\n","\r\n", str_replace("\r","",$htmlBody));
+            $plainBody = str_replace("\n","\r\n", str_replace("\r","",$plainBody));
+
+            if (Request::GetProtocolVersion() >= 12.0) {
+                $output->asbody = new SyncBaseBody();
+
+                switch($bpReturnType) {
+                    case SYNC_BODYPREFERENCE_PLAIN:
+                        $output->asbody->data = $plainBody;
+                        break;
+                    case SYNC_BODYPREFERENCE_HTML:
+                        if ($htmlBody == "") {
+                            $output->asbody->data = $plainBody;
+                            $bpReturnType = SYNC_BODYPREFERENCE_PLAIN;
+                        }
+                        else {
+                            $output->asbody->data = $htmlBody;
+                        }
+                        break;
+                    case SYNC_BODYPREFERENCE_MIME:
+                        //We don't need to create a new MIME mail, we already have one!!
+                        $output->asbody->data = $mail;
+                        break;
+                    case SYNC_BODYPREFERENCE_RTF:
+                        ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->GetMessage RTF Format NOT CHECKED");
+                        $output->asbody->data = base64_encode($plainBody);
+                        break;
+                }
+                // truncate body, if requested
+                if(strlen($output->asbody->data) > $truncsize) {
+                    $output->asbody->data = Utils::Utf8_truncate($output->asbody->data, $truncsize);
+                    $output->asbody->truncated = 1;
+                }
+
+                $output->asbody->type = $bpReturnType;
+                $output->nativebodytype = $bpReturnType;
+                $output->asbody->estimatedDataSize = strlen($output->asbody->data);
+
+                $bpo = $contentparameters->BodyPreference($output->asbody->type);
+                if (Request::GetProtocolVersion() >= 14.0 && $bpo->GetPreview()) {
+                    $output->asbody->preview = Utils::Utf8_truncate(Utils::ConvertHtmlToText($plainBody), $bpo->GetPreview());
+                }
+                else {
+                    $output->asbody->truncated = 0;
+                }
+            }
+            /* END fmbiete's contribution r1528, ZP-320 */
+            else { // ASV_2.5
                 $output->bodytruncated = 0;
-            }
-
-            $output->body = $body;
+                /* BEGIN fmbiete's contribution r1528, ZP-320 */
+                if ($bpReturnType == SYNC_BODYPREFERENCE_MIME) {
+                    if (strlen($mail) > $truncsize) {
+                        $output->mimedata = Utils::Utf8_truncate($mail, $truncsize);
+                        $output->mimetruncated = 1;
+                    }
+                    else {
+                        $output->mimetruncated = 0;
+                        $output->mimedata = $mail;
+                    }
+                    $output->mimesize = strlen($output->mimedata);
+                }
+                else {
+                    // truncate body, if requested
+                    if (strlen($plainBody) > $truncsize) {
+                        $output->body = Utils::Utf8_truncate($plainBody, $truncsize);
+                        $output->bodytruncated = 1;
+                    }
+                    else {
+                        $output->body = $plainBody;
+                        $output->bodytruncated = 0;
+                    }
+                    $output->bodysize = strlen($output->body);
+                }
+                /* END fmbiete's contribution r1528, ZP-320 */
+            }
+
             $output->datereceived = isset($message->headers["date"]) ? $this->cleanupDate($message->headers["date"]) : null;
             $output->messageclass = "IPM.Note";
@@ -991,4 +1124,16 @@
             $output->read = $stat["flags"];
             $output->from = isset($message->headers["from"]) ? $message->headers["from"] : null;
+
+            /* BEGIN fmbiete's contribution r1528, ZP-320 */
+            if (isset($message->headers["thread-topic"])) {
+                $output->threadtopic = $message->headers["thread-topic"];
+            }
+
+            // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
+            $output->internetcpid = INTERNET_CPID_UTF8;
+            if (Request::GetProtocolVersion() >= 12.0) {
+                $output->contentclass = "urn:content-classes:message";
+            }
+            /* END fmbiete's contribution r1528, ZP-320 */
 
             $Mail_RFC822 = new Mail_RFC822();
@@ -1030,4 +1175,6 @@
             if (isset($message->headers["x-priority"])) {
                 $mimeImportance =  preg_replace("/\D+/", "", $message->headers["x-priority"]);
+                //MAIL 1 - most important, 3 - normal, 5 - lowest
+                //AS 0 - low, 1 - normal, 2 - important
                 if ($mimeImportance > 3)
                     $output->importance = 0;
@@ -1036,8 +1183,10 @@
                 if ($mimeImportance < 3)
                     $output->importance = 2;
-            }
-
-            // Attachments are only searched in the top-level part
-            if(isset($message->parts)) {
+            } else { /* fmbiete's contribution r1528, ZP-320 */
+                $output->importance = 1;
+            }
+
+            // Attachments are not needed for MIME messages
+            if($bpReturnType != SYNC_BODYPREFERENCE_MIME && isset($message->parts)) {
                 $mparts = $message->parts;
                 for ($i=0; $i<count($mparts); $i++) {
@@ -1053,12 +1202,4 @@
                         (isset($part->ctype_primary) && $part->ctype_primary != "text")) {
 
-                        if (!isset($output->attachments) || !is_array($output->attachments))
-                            $output->attachments = array();
-
-                        $attachment = new SyncAttachment();
-
-                        if (isset($part->body))
-                            $attachment->attsize = strlen($part->body);
-
                         if(isset($part->d_parameters['filename']))
                             $attname = $part->d_parameters['filename'];
@@ -1069,11 +1210,43 @@
                         else $attname = "unknown attachment";
 
-                        $attachment->displayname = $attname;
-                        $attachment->attname = $folderid . ":" . $id . ":" . $i;
-                        $attachment->attmethod = 1;
-                        $attachment->attoid = isset($part->headers['content-id']) ? $part->headers['content-id'] : "";
-                        array_push($output->attachments, $attachment);
+                        /* BEGIN fmbiete's contribution r1528, ZP-320 */
+                        if (Request::GetProtocolVersion() >= 12.0) {
+                            if (!isset($output->asattachments) || !is_array($output->asattachments))
+                                $output->asattachments = array();
+
+                            $attachment = new SyncBaseAttachment();
+
+                            $attachment->estimatedDataSize = isset($part->d_parameters['size']) ? $part->d_parameters['size'] : isset($part->body) ? strlen($part->body) : 0;
+
+                            $attachment->displayname = $attname;
+                            $attachment->filereference = $folderid . ":" . $id . ":" . $i;
+                            $attachment->method = 1; //Normal attachment
+                            $attachment->contentid = isset($part->headers['content-id']) ? str_replace("<", "", str_replace(">", "", $part->headers['content-id'])) : "";
+                            if (isset($part->disposition) && $part->disposition == "inline") {
+                                $attachment->isinline = 1;
+                            }
+                            else {
+                                $attachment->isinline = 0;
+                            }
+
+                            array_push($output->asattachments, $attachment);
+                        }
+                        else { //ASV_2.5
+                            if (!isset($output->attachments) || !is_array($output->attachments))
+                                $output->attachments = array();
+
+                            $attachment = new SyncAttachment();
+
+                            $attachment->attsize = isset($part->d_parameters['size']) ? $part->d_parameters['size'] : isset($part->body) ? strlen($part->body) : 0;
+
+                            $attachment->displayname = $attname;
+                            $attachment->attname = $folderid . ":" . $id . ":" . $i;
+                            $attachment->attmethod = 1;
+                            $attachment->attoid = isset($part->headers['content-id']) ? str_replace("<", "", str_replace(">", "", $part->headers['content-id'])) : "";
+
+                            array_push($output->attachments, $attachment);
+                        }
+                        /* END fmbiete's contribution r1528, ZP-320 */
                     }
-
                 }
             }
@@ -1081,8 +1254,5 @@
             unset($mobj);
             unset($mail);
-
-            $output->body .= ' '; //Adicionado pois por algum motivo o android corta o ultimo caractere ao fazer a operação maiores detalhes
             return $output;
-
         }
 
@@ -1100,5 +1270,5 @@
      */
     public function StatMessage($folderid, $id) {
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->StatMessage('%s','%s')", $folderid,  $id));
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->StatMessage('%s','%s')", $folderid,  $id));
         $folderImapid = $this->getImapIdFromFolderId($folderid);
 
@@ -1107,5 +1277,5 @@
 
         if (!$overview) {
-            ZLog::Write(LOGLEVEL_WARN, sprintf("ExpressoImapProvider->StatMessage('%s','%s'): Failed to retrieve overview: %s", $folderid,  $id, imap_last_error()));
+            ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->StatMessage('%s','%s'): Failed to retrieve overview: %s", $folderid,  $id, imap_last_error()));
             return false;
         }
@@ -1131,5 +1301,5 @@
     /**
      * Called when a message has been changed on the mobile.
-     * This functionality is not available for emails.
+     * Added support for FollowUp flag
      *
      * @param string        $folderid       id of the folder
@@ -1142,8 +1312,33 @@
      */
     public function ChangeMessage($folderid, $id, $message) {
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->ChangeMessage('%s','%s','%s')", $folderid, $id, get_class($message)));
-        // TODO recheck implementation
-        // TODO this could throw several StatusExceptions like e.g. SYNC_STATUS_OBJECTNOTFOUND, SYNC_STATUS_SYNCCANNOTBECOMPLETED
-        return false;
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->ChangeMessage('%s','%s','%s')", $folderid, $id, get_class($message)));
+
+        /* BEGIN fmbiete's contribution r1529, ZP-321 */
+        if (isset($message->flag)) {
+            ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->ChangeMessage('Setting flag')"));
+
+            $folderImapid = $this->getImapIdFromFolderId($folderid);
+
+            $this->imap_reopenFolder($folderImapid);
+
+            if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
+                ZLog::Write(LOGLEVEL_DEBUG, "Set On FollowUp -> IMAP Flagged");
+                $status = @imap_setflag_full($this->mbox, $id, "\\Flagged",ST_UID);
+            }
+            else {
+                ZLog::Write(LOGLEVEL_DEBUG, "Clearing Flagged");
+                $status = @imap_clearflag_full ( $this->mbox, $id, "\\Flagged", ST_UID);
+            }
+
+            if ($status) {
+                ZLog::Write(LOGLEVEL_DEBUG, "Flagged changed");
+            }
+            else {
+                ZLog::Write(LOGLEVEL_DEBUG, "Flagged failed");
+            }
+        }
+
+        return $this->StatMessage($folderid, $id);
+        /* END fmbiete's contribution r1529, ZP-321 */
     }
 
@@ -1160,5 +1355,5 @@
      */
     public function SetReadFlag($folderid, $id, $flags) {
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->SetReadFlag('%s','%s','%s')", $folderid, $id, $flags));
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->SetReadFlag('%s','%s','%s')", $folderid, $id, $flags));
         $folderImapid = $this->getImapIdFromFolderId($folderid);
 
@@ -1187,5 +1382,5 @@
      */
     public function DeleteMessage($folderid, $id) {
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->DeleteMessage('%s','%s')", $folderid, $id));
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->DeleteMessage('%s','%s')", $folderid, $id));
         $folderImapid = $this->getImapIdFromFolderId($folderid);
 
@@ -1195,5 +1390,5 @@
         $s2 = @imap_expunge($this->mbox);
 
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->DeleteMessage('%s','%s'): result: s-delete: '%s' s-expunge: '%s' setflag: '%s'", $folderid, $id, $s1, $s2, $s11));
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->DeleteMessage('%s','%s'): result: s-delete: '%s' s-expunge: '%s' setflag: '%s'", $folderid, $id, $s1, $s2, $s11));
 
         return ($s1 && $s2 && $s11);
@@ -1212,5 +1407,5 @@
      */
     public function MoveMessage($folderid, $id, $newfolderid) {
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->MoveMessage('%s','%s','%s')", $folderid, $id, $newfolderid));
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s')", $folderid, $id, $newfolderid));
         $folderImapid = $this->getImapIdFromFolderId($folderid);
         $newfolderImapid = $this->getImapIdFromFolderId($newfolderid);
@@ -1225,5 +1420,5 @@
 
         if (!$overview)
-            throw new StatusException(sprintf("ExpressoImapProvider->MoveMessage('%s','%s','%s'): Error, unable to retrieve overview of source message: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
+            throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to retrieve overview of source message: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDSOURCEID);
         else {
             // get next UID for destination folder
@@ -1234,5 +1429,5 @@
             $destStatus = imap_status($this->mbox, $this->server . $newfolderImapid, SA_ALL);
             if (!$destStatus)
-                throw new StatusException(sprintf("ExpressoImapProvider->MoveMessage('%s','%s','%s'): Error, unable to open destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
+                throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, unable to open destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_INVALIDDESTID);
 
             $newid = $destStatus->uidnext;
@@ -1241,5 +1436,5 @@
             $s1 = imap_mail_move($this->mbox, $id, $newfolderImapid, CP_UID);
             if (! $s1)
-                throw new StatusException(sprintf("ExpressoImapProvider->MoveMessage('%s','%s','%s'): Error, copy to destination folder failed: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
+                throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, copy to destination folder failed: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
 
 
@@ -1250,5 +1445,5 @@
             $stat = $this->imap_reopenFolder($newfolderImapid);
             if (! $s1)
-                throw new StatusException(sprintf("ExpressoImapProvider->MoveMessage('%s','%s','%s'): Error, openeing the destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
+                throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, openeing the destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE);
 
 
@@ -1261,5 +1456,5 @@
             $s4 = @imap_setflag_full ($this->mbox, $newid, $newflags, FT_UID);
 
-            ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->MoveMessage('%s','%s','%s'): result s-move: '%s' s-expunge: '%s' unset-Flags: '%s' set-Flags: '%s'", $folderid, $id, $newfolderid, Utils::PrintAsString($s1), Utils::PrintAsString($s2), Utils::PrintAsString($s3), Utils::PrintAsString($s4)));
+            ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): result s-move: '%s' s-expunge: '%s' unset-Flags: '%s' set-Flags: '%s'", $folderid, $id, $newfolderid, Utils::PrintAsString($s1), Utils::PrintAsString($s2), Utils::PrintAsString($s3), Utils::PrintAsString($s4)));
 
             // return the new id "as string""
@@ -1287,13 +1482,13 @@
             if (isset($this->permanentStorage->fmFidFimap[$folderid])) {
                 $imapId = $this->permanentStorage->fmFidFimap[$folderid];
-                ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->getImapIdFromFolderId('%s') = %s", $folderid, $imapId));
+                ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getImapIdFromFolderId('%s') = %s", $folderid, $imapId));
                 return $imapId;
             }
             else {
-                ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->getImapIdFromFolderId('%s') = %s", $folderid, 'not found'));
+                ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getImapIdFromFolderId('%s') = %s", $folderid, 'not found'));
                 return false;
             }
         }
-        ZLog::Write(LOGLEVEL_WARN, sprintf("ExpressoImapProvider->getImapIdFromFolderId('%s') = %s", $folderid, 'not initialized!'));
+        ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->getImapIdFromFolderId('%s') = %s", $folderid, 'not initialized!'));
         return false;
     }
@@ -1313,13 +1508,13 @@
             if (isset($this->permanentStorage->fmFimapFid[$imapid])) {
                 $folderid = $this->permanentStorage->fmFimapFid[$imapid];
-                ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->getFolderIdFromImapId('%s') = %s", $imapid, $folderid));
+                ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getFolderIdFromImapId('%s') = %s", $imapid, $folderid));
                 return $folderid;
             }
             else {
-                ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->getFolderIdFromImapId('%s') = %s", $imapid, 'not found'));
+                ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getFolderIdFromImapId('%s') = %s", $imapid, 'not found'));
                 return false;
             }
         }
-        ZLog::Write(LOGLEVEL_WARN, sprintf("ExpressoImapProvider->getFolderIdFromImapId('%s') = %s", $imapid, 'not initialized!'));
+        ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->getFolderIdFromImapId('%s') = %s", $imapid, 'not initialized!'));
         return false;
     }
@@ -1363,5 +1558,5 @@
         }
 
-        ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->convertImapId('%s') = %s", $imapid, $folderid));
+        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->convertImapId('%s') = %s", $imapid, $folderid));
 
         return $folderid;
@@ -1385,8 +1580,4 @@
         if($body === "") {
             $this->getBodyRecursive($message, "html", $body);
-            // remove css-style tags
-            $body = preg_replace("/<style.*?<\/style>/is", "", $body);
-            // remove all other html
-            $body = strip_tags($body);
         }
 
@@ -1426,5 +1617,5 @@
      */
     protected function getServerDelimiter() {
-        $list = @imap_getmailboxes($this->mbox, $this->server, "*");
+        $list = @imap_getmailboxes($this->mbox, $this->server, "INBOX*");
         if (is_array($list)) {
             $val = $list[0];
@@ -1447,11 +1638,11 @@
     protected function imap_reopenFolder($folderid, $force = false) {
         // to see changes, the folder has to be reopened!
-        if ($this->mboxFolder != $folderid || $force) {
-            $s = @imap_reopen($this->mbox, $this->server . $folderid);
-            // TODO throw status exception
-            if (!$s) {
-                ZLog::Write(LOGLEVEL_WARN, "ExpressoImapProvider->imap_reopenFolder('%s'): failed to change folder: ",$folderid, implode(", ", imap_errors()));
+           if ($this->mboxFolder != $folderid || $force) {
+               $s = @imap_reopen($this->mbox, $this->server . $folderid);
+               // TODO throw status exception
+               if (!$s) {
+                ZLog::Write(LOGLEVEL_WARN, "BackendIMAP->imap_reopenFolder('%s'): failed to change folder: ",$folderid, implode(", ", imap_errors()));
                 return false;
-            }
+               }
             $this->mboxFolder = $folderid;
         }
@@ -1564,5 +1755,5 @@
             foreach($ad as $addr) {
                 if ($addr_string) $addr_string .= ",";
-                $addr_string .= $addr->mailbox . "@" . $addr->host;
+                    $addr_string .= $addr->mailbox . "@" . $addr->host;
             }
         }
@@ -1627,5 +1818,16 @@
     }
 
-}
+    /* BEGIN fmbiete's contribution r1528, ZP-320 */
+    /**
+     * Indicates which AS version is supported by the backend.
+     *
+     * @access public
+     * @return string       AS version constant
+     */
+    public function GetSupportedASVersion() {
+        return ZPush::ASV_14;
+    }
+    /* END fmbiete's contribution r1528, ZP-320 */
+};
 
 ?>
Index: trunk/zpush/backend/expresso/providers/calendarProvider.php
===================================================================
--- trunk/zpush/backend/expresso/providers/calendarProvider.php	(revision 7670)
+++ trunk/zpush/backend/expresso/providers/calendarProvider.php	(revision 7671)
@@ -201,4 +201,5 @@
         $schedulable = Controller::find(array('concept' => 'schedulable'), null , array('filter' => array( '=' , 'uid' , $id)));
         if( is_array($schedulable) && count($schedulable) > 0 )
+
             $schedulable = $schedulable[0];
         else
Index: trunk/zpush/backend/expresso/expresso.php
===================================================================
--- trunk/zpush/backend/expresso/expresso.php	(revision 7670)
+++ trunk/zpush/backend/expresso/expresso.php	(revision 7671)
@@ -32,13 +32,9 @@
             {
                 if($folder['id'] == $folderId && is_object($this->providerInstances[$provider]))
-                {
                     return $this->providerInstances[$provider];
-                }
-                else
-                {
-                     throw new Exception('Error in get Provider');
-                }
             }
         }
+
+        throw new FatalException("BackendExpresso->getProvider(): Provide not found", 0, null, LOGLEVEL_FATAL);
     }
 
