Changeset 7671


Ignore:
Timestamp:
12/18/12 15:08:46 (11 years ago)
Author:
cristiano
Message:

Ticket #3209 - Atualizações de lib e correções de config

Location:
trunk/zpush
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/zpush/backend/expresso/expresso.php

    r7670 r7671  
    3232            { 
    3333                if($folder['id'] == $folderId && is_object($this->providerInstances[$provider])) 
    34                 { 
    3534                    return $this->providerInstances[$provider]; 
    36                 } 
    37                 else 
    38                 { 
    39                      throw new Exception('Error in get Provider'); 
    40                 } 
    4135            } 
    4236        } 
     37 
     38        throw new FatalException("BackendExpresso->getProvider(): Provide not found", 0, null, LOGLEVEL_FATAL); 
    4339    } 
    4440 
  • trunk/zpush/backend/expresso/providers/calendarProvider.php

    r7670 r7671  
    201201        $schedulable = Controller::find(array('concept' => 'schedulable'), null , array('filter' => array( '=' , 'uid' , $id))); 
    202202        if( is_array($schedulable) && count($schedulable) > 0 ) 
     203 
    203204            $schedulable = $schedulable[0]; 
    204205        else 
  • trunk/zpush/backend/expresso/providers/imapProvider.php

    r7644 r7671  
    11<?php 
    22/*********************************************** 
    3  * File      :   imap.php 
    4  * Project   :   Z-Push 
    5  * Descr     :   This backend is based on 
    6  *               'BackendDiff' and implements an 
    7  *               IMAP interface 
    8  * 
    9  * Created   :   10.10.2007 
    10  * 
    11  * Copyright 2007 - 2012 Zarafa Deutschland GmbH 
    12  * 
    13  * This program is free software: you can redistribute it and/or modify 
    14  * it under the terms of the GNU Affero General Public License, version 3, 
    15  * as published by the Free Software Foundation with the following additional 
    16  * term according to sec. 7: 
    17  * 
    18  * According to sec. 7 of the GNU Affero General Public License, version 3, 
    19  * the terms of the AGPL are supplemented with the following terms: 
    20  * 
    21  * "Zarafa" is a registered trademark of Zarafa B.V. 
    22  * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH 
    23  * The licensing of the Program under the AGPL does not imply a trademark license. 
    24  * Therefore any rights, title and interest in our trademarks remain entirely with us. 
    25  * 
    26  * However, if you propagate an unmodified version of the Program you are 
    27  * allowed to use the term "Z-Push" to indicate that you distribute the Program. 
    28  * Furthermore you may use our trademarks where it is necessary to indicate 
    29  * the intended purpose of a product or service provided you use it in accordance 
    30  * with honest practices in industrial or commercial matters. 
    31  * If you want to propagate modified versions of the Program under the name "Z-Push", 
    32  * you may only do so if you have a written permission by Zarafa Deutschland GmbH 
    33  * (to acquire a permission please contact Zarafa at trademark@zarafa.com). 
    34  * 
    35  * This program is distributed in the hope that it will be useful, 
    36  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    37  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
    38  * GNU Affero General Public License for more details. 
    39  * 
    40  * You should have received a copy of the GNU Affero General Public License 
    41  * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
    42  * 
    43  * Consult LICENSE file for details 
    44  ************************************************/ 
     3* File      :   imap.php 
     4* Project   :   Z-Push 
     5* Descr     :   This backend is based on 
     6*               'BackendDiff' and implements an 
     7*               IMAP interface 
     8* 
     9* Created   :   10.10.2007 
     10* 
     11* Copyright 2007 - 2012 Zarafa Deutschland GmbH 
     12* 
     13* This program is free software: you can redistribute it and/or modify 
     14* it under the terms of the GNU Affero General Public License, version 3, 
     15* as published by the Free Software Foundation with the following additional 
     16* term according to sec. 7: 
     17* 
     18* According to sec. 7 of the GNU Affero General Public License, version 3, 
     19* the terms of the AGPL are supplemented with the following terms: 
     20* 
     21* "Zarafa" is a registered trademark of Zarafa B.V. 
     22* "Z-Push" is a registered trademark of Zarafa Deutschland GmbH 
     23* The licensing of the Program under the AGPL does not imply a trademark license. 
     24* Therefore any rights, title and interest in our trademarks remain entirely with us. 
     25* 
     26* However, if you propagate an unmodified version of the Program you are 
     27* allowed to use the term "Z-Push" to indicate that you distribute the Program. 
     28* Furthermore you may use our trademarks where it is necessary to indicate 
     29* the intended purpose of a product or service provided you use it in accordance 
     30* with honest practices in industrial or commercial matters. 
     31* If you want to propagate modified versions of the Program under the name "Z-Push", 
     32* you may only do so if you have a written permission by Zarafa Deutschland GmbH 
     33* (to acquire a permission please contact Zarafa at trademark@zarafa.com). 
     34* 
     35* This program is distributed in the hope that it will be useful, 
     36* but WITHOUT ANY WARRANTY; without even the implied warranty of 
     37* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
     38* GNU Affero General Public License for more details. 
     39* 
     40* You should have received a copy of the GNU Affero General Public License 
     41* along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     42* 
     43* Consult LICENSE file for details 
     44************************************************/ 
    4545 
    4646include_once(__DIR__.'/../../../lib/default/diffbackend/diffbackend.php'); 
     
    6060    protected $sinkfolders; 
    6161    protected $sinkstates; 
     62    protected $excludedFolders; /* fmbiete's contribution r1527, ZP-319 */ 
    6263 
    6364    /**---------------------------------------------------------------------------------------------------------- 
     
    8283 
    8384        if (!function_exists("imap_open")) 
    84             throw new FatalException("ExpressoImapProvider(): php-imap module is not installed", 0, null, LOGLEVEL_FATAL); 
     85            throw new FatalException("BackendIMAP(): php-imap module is not installed", 0, null, LOGLEVEL_FATAL); 
     86 
     87        /* BEGIN fmbiete's contribution r1527, ZP-319 */ 
     88        $this->excludedFolders = array(); 
     89        if (defined('IMAP_EXCLUDED_FOLDERS')) { 
     90            $this->excludedFolders = explode("|", IMAP_EXCLUDED_FOLDERS); 
     91            ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->Logon(): Excluding Folders (%s)", IMAP_EXCLUDED_FOLDERS)); 
     92        } 
     93        /* END fmbiete's contribution r1527, ZP-319 */ 
    8594 
    8695        // open the IMAP-mailbox 
     
    115124 
    116125        if ($this->mbox) { 
    117             ZLog::Write(LOGLEVEL_INFO, sprintf("ExpressoImapProvider->Logon(): User '%s' is authenticated on IMAP",$username)); 
     126            ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->Logon(): User '%s' is authenticated on IMAP",$username)); 
    118127            $this->username = $username; 
    119128            $this->domain = $domain; 
     
    123132        } 
    124133        else { 
    125             ZLog::Write(LOGLEVEL_ERROR, "ExpressoImapProvider->Logon(): can't connect: " . imap_last_error()); 
     134            ZLog::Write(LOGLEVEL_ERROR, "BackendIMAP->Logon(): can't connect: " . imap_last_error()); 
    126135            return false; 
    127136        } 
     
    141150            $errors = imap_errors(); 
    142151            if (is_array($errors)) { 
    143                 foreach ($errors as $e) 
    144                     if (stripos($e, "fail") !== false) 
     152                foreach ($errors as $e) { 
     153                    if (stripos($e, "fail") !== false) { 
    145154                        $level = LOGLEVEL_WARN; 
    146                     else 
     155                    } 
     156                    else { 
    147157                        $level = LOGLEVEL_DEBUG; 
    148  
    149                 ZLog::Write($level, "ExpressoImapProvider->Logoff(): IMAP said: " . $e); 
     158                    } 
     159                    ZLog::Write($level, "BackendIMAP->Logoff(): IMAP said: " . $e); 
     160                } 
    150161            } 
    151162            @imap_close($this->mbox); 
    152             ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->Logoff(): IMAP connection closed"); 
     163            ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->Logoff(): IMAP connection closed"); 
    153164        } 
    154165        $this->SaveStorages(); 
     
    171182 
    172183        ZLog::Write(LOGLEVEL_DEBUG, sprintf("IMAPBackend->SendMail(): RFC822: %d bytes  forward-id: '%s' reply-id: '%s' parent-id: '%s' SaveInSent: '%s' ReplaceMIME: '%s'", 
    173             strlen($sm->mime), Utils::PrintAsString($sm->forwardflag), Utils::PrintAsString($sm->replyflag), 
    174             Utils::PrintAsString((isset($sm->source->folderid) ? $sm->source->folderid : false)), 
    175             Utils::PrintAsString(($sm->saveinsent)), Utils::PrintAsString(isset($sm->replacemime)) )); 
     184                                            strlen($sm->mime), Utils::PrintAsString($sm->forwardflag), Utils::PrintAsString($sm->replyflag), 
     185                                            Utils::PrintAsString((isset($sm->source->folderid) ? $sm->source->folderid : false)), 
     186                                            Utils::PrintAsString(($sm->saveinsent)), Utils::PrintAsString(isset($sm->replacemime)) )); 
    176187 
    177188        if (isset($sm->source->folderid) && $sm->source->folderid) 
     
    307318            $origmail = @imap_fetchheader($this->mbox, $reply, FT_UID) . @imap_body($this->mbox, $reply, FT_PEEK | FT_UID); 
    308319            if (!$origmail) 
    309                 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); 
     320                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); 
    310321 
    311322            $mobj2 = new Mail_mimeDecode($origmail); 
     
    329340 
    330341            if (!$origmail) 
    331                 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); 
     342                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); 
    332343 
    333344            if (!defined('IMAP_INLINE_FORWARD') || IMAP_INLINE_FORWARD === false) { 
     
    370381                    $nbody = chunk_split(base64_encode($nbody)); 
    371382                    if ($use_orgbody) 
    372                         // contrib - chunk base64 encoded body 
     383                    // contrib - chunk base64 encoded body 
    373384                        $repl_body = chunk_split(base64_encode($repl_body)); 
    374385                } 
    375386 
    376387                if ($use_orgbody) { 
    377                     ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): -------------------"); 
    378                     ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): old:\n'$repl_body'\nnew:\n'$nbody'\nund der body:\n'$body'"); 
     388                    ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): -------------------"); 
     389                    ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): old:\n'$repl_body'\nnew:\n'$nbody'\nund der body:\n'$body'"); 
    379390                    //$body is quoted-printable encoded while $repl_body and $nbody are plain text, 
    380391                    //so we need to decode $body in order replace to take place 
     
    434445                        //2. multipart/alternative part which is the original message 
    435446                        $body = "This is a message with multiple parts in MIME format.\n--". 
    436                             $att_boundary. 
    437                             "\nContent-Type: $forward_h_ct\nContent-Transfer-Encoding: $forward_h_cte\n\n". 
    438                             (($body_base64) ? chunk_split(base64_encode($message->body)) : rtrim($message->body)). 
    439                             "\n--".$att_boundary. 
    440                             "\nContent-Type: {$mess2->headers['content-type']}\n\n". 
    441                             @imap_body($this->mbox, $forward, FT_PEEK | FT_UID)."\n\n"; 
     447                                $att_boundary. 
     448                                "\nContent-Type: $forward_h_ct\nContent-Transfer-Encoding: $forward_h_cte\n\n". 
     449                                (($body_base64) ? chunk_split(base64_encode($message->body)) : rtrim($message->body)). 
     450                                "\n--".$att_boundary. 
     451                                "\nContent-Type: {$mess2->headers['content-type']}\n\n". 
     452                                @imap_body($this->mbox, $forward, FT_PEEK | FT_UID)."\n\n"; 
    442453                    } 
    443454                    $body .= "--$att_boundary--\n\n"; 
     
    458469            if (!empty($forward_h_ct)) $headers .= "\nContent-Type: $forward_h_ct"; 
    459470            if (!empty($forward_h_cte)) $headers .= "\nContent-Transfer-Encoding: $forward_h_cte"; 
    460             //  if body was quoted-printable, convert it again 
     471        //  if body was quoted-printable, convert it again 
    461472            if (isset($message->headers["content-transfer-encoding"]) && strtolower($message->headers["content-transfer-encoding"]) == "quoted-printable") { 
    462473                $body = quoted_printable_encode($body); 
     
    465476 
    466477        // more debugging 
    467         ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): parsed message: ". print_r($message,1)); 
    468         ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): headers: $headers"); 
    469         ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): subject: {$message->headers["subject"]}"); 
    470         ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): body: $body"); 
     478        ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): parsed message: ". print_r($message,1)); 
     479        ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): headers: $headers"); 
     480        /* BEGIN fmbiete's contribution r1528, ZP-320 */ 
     481        if (isset($message->headers["subject"])) { 
     482            ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): subject: {$message->headers["subject"]}"); 
     483        } 
     484        else { 
     485            ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): subject: no subject set. Set to empty."); 
     486            $message->headers["subject"] = ""; // added by mku ZP-330 
     487        } 
     488        /* END fmbiete's contribution r1528, ZP-320 */ 
     489        ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): body: $body"); 
    471490 
    472491        if (!defined('IMAP_USE_IMAPMAIL') || IMAP_USE_IMAPMAIL == true) { 
     492            // changed by mku ZP-330 
    473493            $send =  @imap_mail ( $toaddr, $message->headers["subject"], $body, $headers, $ccaddr, $bccaddr); 
    474494        } 
     
    476496            if (!empty($ccaddr))  $headers .= "\nCc: $ccaddr"; 
    477497            if (!empty($bccaddr)) $headers .= "\nBcc: $bccaddr"; 
     498            // changed by mku ZP-330 
    478499            $send =  @mail ( $toaddr, $message->headers["subject"], $body, $headers, $envelopefrom ); 
    479500        } 
     
    481502        // email sent? 
    482503        if (!$send) 
    483             throw new StatusException(sprintf("ExpressoImapProvider->SendMail(): The email could not be sent. Last IMAP-error: %s", imap_last_error()), SYNC_COMMONSTATUS_MAILSUBMISSIONFAILED); 
     504            throw new StatusException(sprintf("BackendIMAP->SendMail(): The email could not be sent. Last IMAP-error: %s", imap_last_error()), SYNC_COMMONSTATUS_MAILSUBMISSIONFAILED); 
    484505 
    485506        // add message to the sent folder 
    486507        // build complete headers 
    487508        $headers .= "\nTo: $toaddr"; 
    488         $headers .= "\nSubject: " . $message->headers["subject"]; 
     509        $headers .= "\nSubject: " . $message->headers["subject"]; // changed by mku ZP-330 
    489510 
    490511        if (!defined('IMAP_USE_IMAPMAIL') || IMAP_USE_IMAPMAIL == true) { 
     
    492513            if (!empty($bccaddr)) $headers .= "\nBcc: $bccaddr"; 
    493514        } 
    494         ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): complete headers: $headers"); 
     515        ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): complete headers: $headers"); 
    495516 
    496517        $asf = false; 
     
    500521        else if (IMAP_SENTFOLDER) { 
    501522            $asf = $this->addSentMessage(IMAP_SENTFOLDER, $headers, $body); 
    502             ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->SendMail(): Outgoing mail saved in configured 'Sent' folder '%s': %s", IMAP_SENTFOLDER, Utils::PrintAsString($asf))); 
     523            ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->SendMail(): Outgoing mail saved in configured 'Sent' folder '%s': %s", IMAP_SENTFOLDER, Utils::PrintAsString($asf))); 
    503524        } 
    504525        // No Sent folder set, try defaults 
    505526        else { 
    506             ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): No Sent mailbox set"); 
     527            ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): No Sent mailbox set"); 
    507528            if($this->addSentMessage("INBOX.Sent", $headers, $body)) { 
    508                 ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): Outgoing mail saved in 'INBOX.Sent'"); 
     529                ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): Outgoing mail saved in 'INBOX.Sent'"); 
    509530                $asf = true; 
    510531            } 
    511532            else if ($this->addSentMessage("Sent", $headers, $body)) { 
    512                 ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail(): Outgoing mail saved in 'Sent'"); 
     533                ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail(): Outgoing mail saved in 'Sent'"); 
    513534                $asf = true; 
    514535            } 
    515536            else if ($this->addSentMessage("Sent Items", $headers, $body)) { 
    516                 ZLog::Write(LOGLEVEL_DEBUG, "ExpressoImapProvider->SendMail():IMAP-SendMail: Outgoing mail saved in 'Sent Items'"); 
     537                ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->SendMail():IMAP-SendMail: Outgoing mail saved in 'Sent Items'"); 
    517538                $asf = true; 
    518539            } 
     
    520541 
    521542        if (!$asf) { 
    522             ZLog::Write(LOGLEVEL_ERROR, "ExpressoImapProvider->SendMail(): The email could not be saved to Sent Items folder. Check your configuration."); 
     543            ZLog::Write(LOGLEVEL_ERROR, "BackendIMAP->SendMail(): The email could not be saved to Sent Items folder. Check your configuration."); 
    523544        } 
    524545 
     
    560581     */ 
    561582    public function GetAttachmentData($attname) { 
    562         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->GetAttachmentData('%s')", $attname)); 
     583        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetAttachmentData('%s')", $attname)); 
    563584 
    564585        list($folderid, $id, $part) = explode(":", $attname); 
    565586 
    566587        if (!$folderid || !$id || !$part) 
    567             throw new StatusException(sprintf("ExpressoImapProvider->GetAttachmentData('%s'): Error, attachment name key can not be parsed", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); 
     588            throw new StatusException(sprintf("BackendIMAP->GetAttachmentData('%s'): Error, attachment name key can not be parsed", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); 
    568589 
    569590        // convert back to work on an imap-id 
     
    576597        $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8')); 
    577598 
    578         if (!isset($message->parts[$part]->body)) 
    579             throw new StatusException(sprintf("ExpressoImapProvider->GetAttachmentData('%s'): Error, requested part key can not be found: '%d'", $attname, $part), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); 
     599        /* BEGIN fmbiete's contribution r1528, ZP-320 */ 
     600        //trying parts 
     601        $mparts = $message->parts; 
     602        for ($i = 0; $i < count($mparts); $i++) { 
     603            $auxpart = $mparts[$i]; 
     604            //recursively add parts 
     605            if($auxpart->ctype_primary == "multipart" && ($auxpart->ctype_secondary == "mixed" || $auxpart->ctype_secondary == "alternative"  || $auxpart->ctype_secondary == "related")) { 
     606                foreach($auxpart->parts as $spart) 
     607                    $mparts[] = $spart; 
     608            } 
     609        } 
     610        /* END fmbiete's contribution r1528, ZP-320 */ 
     611 
     612        if (!isset($mparts[$part]->body)) 
     613            throw new StatusException(sprintf("BackendIMAP->GetAttachmentData('%s'): Error, requested part key can not be found: '%d'", $attname, $part), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); 
    580614 
    581615        // unset mimedecoder & mail 
     
    585619        include_once('include/stringstreamwrapper.php'); 
    586620        $attachment = new SyncItemOperationsAttachment(); 
    587         $attachment->data = StringStreamWrapper::Open($message->parts[$part]->body); 
    588         if (isset($message->parts[$part]->ctype_primary) && isset($message->parts[$part]->ctype_secondary)) 
    589             $attachment->contenttype = $message->parts[$part]->ctype_primary .'/'.$message->parts[$part]->ctype_secondary; 
     621        /* BEGIN fmbiete's contribution r1528, ZP-320 */ 
     622        $attachment->data = StringStreamWrapper::Open($mparts[$part]->body); 
     623        if (isset($mparts[$part]->ctype_primary) && isset($mparts[$part]->ctype_secondary)) 
     624            $attachment->contenttype = $mparts[$part]->ctype_primary .'/'.$mparts[$part]->ctype_secondary; 
     625 
     626        unset($mparts); 
     627        unset($message); 
     628 
     629        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetAttachmentData contenttype %s", $attachment->contenttype)); 
     630        /* END fmbiete's contribution r1528, ZP-320 */ 
    590631 
    591632        return $attachment; 
     
    690731        $folders = array(); 
    691732 
    692         $list = @imap_getmailboxes($this->mbox, $this->server, "INBOX*"); 
     733        $list = @imap_getmailboxes($this->mbox, $this->server, "*"); 
    693734        if (is_array($list)) { 
    694735            // reverse list to obtain folders in right order 
     
    696737 
    697738            foreach ($list as $val) { 
    698                 $box = array(); 
    699                 // cut off serverstring 
    700                 $imapid = substr($val->name, strlen($this->server)); 
    701                 $box["id"] = $this->convertImapId($imapid); 
    702  
    703                 $fhir = explode($val->delimiter, $imapid); 
    704                 if (count($fhir) > 1) { 
    705                     $this->getModAndParentNames($fhir, $box["mod"], $imapparent); 
    706                     $box["parent"] = $this->convertImapId($imapparent); 
    707                 } 
    708                 else { 
    709                     $box["mod"] = $imapid; 
    710                     $box["parent"] = "0"; 
    711                 } 
    712                 $folders[]=$box; 
     739                /* BEGIN fmbiete's contribution r1527, ZP-319 */ 
     740                // don't return the excluded folders 
     741                $notExcluded = true; 
     742                for ($i = 0, $cnt = count($this->excludedFolders); $notExcluded && $i < $cnt; $i++) { // expr1, expr2 modified by mku ZP-329 
     743                    // fix exclude folders with special chars by mku ZP-329 
     744                    if (strpos(strtolower($val->name), strtolower(Utils::Utf7_iconv_encode(Utils::Utf8_to_utf7($this->excludedFolders[$i])))) !== false) { 
     745                        $notExcluded = false; 
     746                        ZLog::Write(LOGLEVEL_DEBUG, sprintf("Pattern: <%s> found, excluding folder: '%s'", $this->excludedFolders[$i], $val->name)); // sprintf added by mku ZP-329 
     747                    } 
     748                } 
     749 
     750                if ($notExcluded) { 
     751                    $box = array(); 
     752                    // cut off serverstring 
     753                    $imapid = substr($val->name, strlen($this->server)); 
     754                    $box["id"] = $this->convertImapId($imapid); 
     755 
     756                    $fhir = explode($val->delimiter, $imapid); 
     757                    if (count($fhir) > 1) { 
     758                        $this->getModAndParentNames($fhir, $box["mod"], $imapparent); 
     759                        $box["parent"] = $this->convertImapId($imapparent); 
     760                    } 
     761                    else { 
     762                        $box["mod"] = $imapid; 
     763                        $box["parent"] = "0"; 
     764                    } 
     765                    $folders[]=$box; 
     766                    /* END fmbiete's contribution r1527, ZP-319 */ 
     767                } 
    713768            } 
    714769        } 
    715770        else { 
    716             ZLog::Write(LOGLEVEL_WARN, "ExpressoImapProvider->GetFolderList(): imap_list failed: " . imap_last_error()); 
     771            ZLog::Write(LOGLEVEL_WARN, "BackendIMAP->GetFolderList(): imap_list failed: " . imap_last_error()); 
    717772            return false; 
    718773        } 
     
    795850                $folder->parentid = "0"; 
    796851            } 
    797             $folder->type = SYNC_FOLDER_TYPE_OTHER; 
     852            $folder->type = SYNC_FOLDER_TYPE_USER_MAIL; 
    798853        } 
    799854 
    800855        //advanced debugging 
    801         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->GetFolder('%s'): '%s'", $id, $folder)); 
     856        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetFolder('%s'): '%s'", $id, $folder)); 
    802857 
    803858        return $folder; 
     
    838893     */ 
    839894    public function ChangeFolder($folderid, $oldid, $displayname, $type){ 
    840         ZLog::Write(LOGLEVEL_INFO, sprintf("ExpressoImapProvider->ChangeFolder('%s','%s','%s','%s')", $folderid, $oldid, $displayname, $type)); 
     895        ZLog::Write(LOGLEVEL_INFO, sprintf("BackendIMAP->ChangeFolder('%s','%s','%s','%s')", $folderid, $oldid, $displayname, $type)); 
    841896 
    842897        // go to parent mailbox 
     
    891946     */ 
    892947    public function GetMessageList($folderid, $cutoffdate) { 
    893         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->GetMessageList('%s','%s')", $folderid, $cutoffdate)); 
     948        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessageList('%s','%s')", $folderid, $cutoffdate)); 
    894949 
    895950        $folderid = $this->getImapIdFromFolderId($folderid); 
     
    907962                $sequence = implode(",", $search); 
    908963        } 
    909         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->GetMessageList(): searching with sequence '%s'", $sequence)); 
     964        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessageList(): searching with sequence '%s'", $sequence)); 
    910965        $overviews = @imap_fetch_overview($this->mbox, $sequence); 
    911966 
    912967        if (!$overviews || !is_array($overviews)) { 
    913             ZLog::Write(LOGLEVEL_WARN, sprintf("ExpressoImapProvider->GetMessageList('%s','%s'): Failed to retrieve overview: %s",$folderid, $cutoffdate, imap_last_error())); 
     968            ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->GetMessageList('%s','%s'): Failed to retrieve overview: %s",$folderid, $cutoffdate, imap_last_error())); 
    914969            return $messages; 
    915970        } 
     
    925980 
    926981            // cut of deleted messages 
    927             if (array_key_exists( "deleted", $vars) && $overview->deleted) 
     982            if (array_key_exists("deleted", $vars) && $overview->deleted) 
    928983                continue; 
    929984 
    930             if (array_key_exists( "uid", $vars)) { 
     985            if (array_key_exists("uid", $vars)) { 
    931986                $message = array(); 
    932987                $message["mod"] = $date; 
     
    9571012        $truncsize = Utils::GetTruncSize($contentparameters->GetTruncation()); 
    9581013        $mimesupport = $contentparameters->GetMimeSupport(); 
    959         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->GetMessage('%s','%s')", $folderid,  $id)); 
     1014        $bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */ 
     1015        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage('%s','%s')", $folderid,  $id)); 
    9601016 
    9611017        $folderImapid = $this->getImapIdFromFolderId($folderid); 
     
    9711027            $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8')); 
    9721028 
     1029            /* BEGIN fmbiete's contribution r1528, ZP-320 */ 
    9731030            $output = new SyncMail(); 
    9741031 
    975             $body = $this->getBody($message); 
    976             $output->bodysize = strlen($body); 
    977  
    978             // truncate body, if requested 
    979             if(strlen($body) > $truncsize) { 
    980                 $body = Utils::Utf8_truncate($body, $truncsize); 
    981                 $output->bodytruncated = 1; 
    982             } else { 
    983                 $body = $body; 
     1032            //Select body type preference 
     1033            $bpReturnType = SYNC_BODYPREFERENCE_PLAIN; 
     1034            if ($bodypreference !== false) { 
     1035                $bpReturnType = Utils::GetBodyPreferenceBestMatch($bodypreference); // changed by mku ZP-330 
     1036            } 
     1037            ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage - getBodyPreferenceBestMatch: %d", $bpReturnType)); 
     1038 
     1039            //Get body data 
     1040            $this->getBodyRecursive($message, "plain", $plainBody); 
     1041            $this->getBodyRecursive($message, "html", $htmlBody); 
     1042            if ($plainBody == "") { 
     1043                $plainBody = Utils::ConvertHtmlToText($htmlBody); 
     1044            } 
     1045            $htmlBody = str_replace("\n","\r\n", str_replace("\r","",$htmlBody)); 
     1046            $plainBody = str_replace("\n","\r\n", str_replace("\r","",$plainBody)); 
     1047 
     1048            if (Request::GetProtocolVersion() >= 12.0) { 
     1049                $output->asbody = new SyncBaseBody(); 
     1050 
     1051                switch($bpReturnType) { 
     1052                    case SYNC_BODYPREFERENCE_PLAIN: 
     1053                        $output->asbody->data = $plainBody; 
     1054                        break; 
     1055                    case SYNC_BODYPREFERENCE_HTML: 
     1056                        if ($htmlBody == "") { 
     1057                            $output->asbody->data = $plainBody; 
     1058                            $bpReturnType = SYNC_BODYPREFERENCE_PLAIN; 
     1059                        } 
     1060                        else { 
     1061                            $output->asbody->data = $htmlBody; 
     1062                        } 
     1063                        break; 
     1064                    case SYNC_BODYPREFERENCE_MIME: 
     1065                        //We don't need to create a new MIME mail, we already have one!! 
     1066                        $output->asbody->data = $mail; 
     1067                        break; 
     1068                    case SYNC_BODYPREFERENCE_RTF: 
     1069                        ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->GetMessage RTF Format NOT CHECKED"); 
     1070                        $output->asbody->data = base64_encode($plainBody); 
     1071                        break; 
     1072                } 
     1073                // truncate body, if requested 
     1074                if(strlen($output->asbody->data) > $truncsize) { 
     1075                    $output->asbody->data = Utils::Utf8_truncate($output->asbody->data, $truncsize); 
     1076                    $output->asbody->truncated = 1; 
     1077                } 
     1078 
     1079                $output->asbody->type = $bpReturnType; 
     1080                $output->nativebodytype = $bpReturnType; 
     1081                $output->asbody->estimatedDataSize = strlen($output->asbody->data); 
     1082 
     1083                $bpo = $contentparameters->BodyPreference($output->asbody->type); 
     1084                if (Request::GetProtocolVersion() >= 14.0 && $bpo->GetPreview()) { 
     1085                    $output->asbody->preview = Utils::Utf8_truncate(Utils::ConvertHtmlToText($plainBody), $bpo->GetPreview()); 
     1086                } 
     1087                else { 
     1088                    $output->asbody->truncated = 0; 
     1089                } 
     1090            } 
     1091            /* END fmbiete's contribution r1528, ZP-320 */ 
     1092            else { // ASV_2.5 
    9841093                $output->bodytruncated = 0; 
    985             } 
    986  
    987             $output->body = $body; 
     1094                /* BEGIN fmbiete's contribution r1528, ZP-320 */ 
     1095                if ($bpReturnType == SYNC_BODYPREFERENCE_MIME) { 
     1096                    if (strlen($mail) > $truncsize) { 
     1097                        $output->mimedata = Utils::Utf8_truncate($mail, $truncsize); 
     1098                        $output->mimetruncated = 1; 
     1099                    } 
     1100                    else { 
     1101                        $output->mimetruncated = 0; 
     1102                        $output->mimedata = $mail; 
     1103                    } 
     1104                    $output->mimesize = strlen($output->mimedata); 
     1105                } 
     1106                else { 
     1107                    // truncate body, if requested 
     1108                    if (strlen($plainBody) > $truncsize) { 
     1109                        $output->body = Utils::Utf8_truncate($plainBody, $truncsize); 
     1110                        $output->bodytruncated = 1; 
     1111                    } 
     1112                    else { 
     1113                        $output->body = $plainBody; 
     1114                        $output->bodytruncated = 0; 
     1115                    } 
     1116                    $output->bodysize = strlen($output->body); 
     1117                } 
     1118                /* END fmbiete's contribution r1528, ZP-320 */ 
     1119            } 
     1120 
    9881121            $output->datereceived = isset($message->headers["date"]) ? $this->cleanupDate($message->headers["date"]) : null; 
    9891122            $output->messageclass = "IPM.Note"; 
     
    9911124            $output->read = $stat["flags"]; 
    9921125            $output->from = isset($message->headers["from"]) ? $message->headers["from"] : null; 
     1126 
     1127            /* BEGIN fmbiete's contribution r1528, ZP-320 */ 
     1128            if (isset($message->headers["thread-topic"])) { 
     1129                $output->threadtopic = $message->headers["thread-topic"]; 
     1130            } 
     1131 
     1132            // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx 
     1133            $output->internetcpid = INTERNET_CPID_UTF8; 
     1134            if (Request::GetProtocolVersion() >= 12.0) { 
     1135                $output->contentclass = "urn:content-classes:message"; 
     1136            } 
     1137            /* END fmbiete's contribution r1528, ZP-320 */ 
    9931138 
    9941139            $Mail_RFC822 = new Mail_RFC822(); 
     
    10301175            if (isset($message->headers["x-priority"])) { 
    10311176                $mimeImportance =  preg_replace("/\D+/", "", $message->headers["x-priority"]); 
     1177                //MAIL 1 - most important, 3 - normal, 5 - lowest 
     1178                //AS 0 - low, 1 - normal, 2 - important 
    10321179                if ($mimeImportance > 3) 
    10331180                    $output->importance = 0; 
     
    10361183                if ($mimeImportance < 3) 
    10371184                    $output->importance = 2; 
    1038             } 
    1039  
    1040             // Attachments are only searched in the top-level part 
    1041             if(isset($message->parts)) { 
     1185            } else { /* fmbiete's contribution r1528, ZP-320 */ 
     1186                $output->importance = 1; 
     1187            } 
     1188 
     1189            // Attachments are not needed for MIME messages 
     1190            if($bpReturnType != SYNC_BODYPREFERENCE_MIME && isset($message->parts)) { 
    10421191                $mparts = $message->parts; 
    10431192                for ($i=0; $i<count($mparts); $i++) { 
     
    10531202                        (isset($part->ctype_primary) && $part->ctype_primary != "text")) { 
    10541203 
    1055                         if (!isset($output->attachments) || !is_array($output->attachments)) 
    1056                             $output->attachments = array(); 
    1057  
    1058                         $attachment = new SyncAttachment(); 
    1059  
    1060                         if (isset($part->body)) 
    1061                             $attachment->attsize = strlen($part->body); 
    1062  
    10631204                        if(isset($part->d_parameters['filename'])) 
    10641205                            $attname = $part->d_parameters['filename']; 
     
    10691210                        else $attname = "unknown attachment"; 
    10701211 
    1071                         $attachment->displayname = $attname; 
    1072                         $attachment->attname = $folderid . ":" . $id . ":" . $i; 
    1073                         $attachment->attmethod = 1; 
    1074                         $attachment->attoid = isset($part->headers['content-id']) ? $part->headers['content-id'] : ""; 
    1075                         array_push($output->attachments, $attachment); 
     1212                        /* BEGIN fmbiete's contribution r1528, ZP-320 */ 
     1213                        if (Request::GetProtocolVersion() >= 12.0) { 
     1214                            if (!isset($output->asattachments) || !is_array($output->asattachments)) 
     1215                                $output->asattachments = array(); 
     1216 
     1217                            $attachment = new SyncBaseAttachment(); 
     1218 
     1219                            $attachment->estimatedDataSize = isset($part->d_parameters['size']) ? $part->d_parameters['size'] : isset($part->body) ? strlen($part->body) : 0; 
     1220 
     1221                            $attachment->displayname = $attname; 
     1222                            $attachment->filereference = $folderid . ":" . $id . ":" . $i; 
     1223                            $attachment->method = 1; //Normal attachment 
     1224                            $attachment->contentid = isset($part->headers['content-id']) ? str_replace("<", "", str_replace(">", "", $part->headers['content-id'])) : ""; 
     1225                            if (isset($part->disposition) && $part->disposition == "inline") { 
     1226                                $attachment->isinline = 1; 
     1227                            } 
     1228                            else { 
     1229                                $attachment->isinline = 0; 
     1230                            } 
     1231 
     1232                            array_push($output->asattachments, $attachment); 
     1233                        } 
     1234                        else { //ASV_2.5 
     1235                            if (!isset($output->attachments) || !is_array($output->attachments)) 
     1236                                $output->attachments = array(); 
     1237 
     1238                            $attachment = new SyncAttachment(); 
     1239 
     1240                            $attachment->attsize = isset($part->d_parameters['size']) ? $part->d_parameters['size'] : isset($part->body) ? strlen($part->body) : 0; 
     1241 
     1242                            $attachment->displayname = $attname; 
     1243                            $attachment->attname = $folderid . ":" . $id . ":" . $i; 
     1244                            $attachment->attmethod = 1; 
     1245                            $attachment->attoid = isset($part->headers['content-id']) ? str_replace("<", "", str_replace(">", "", $part->headers['content-id'])) : ""; 
     1246 
     1247                            array_push($output->attachments, $attachment); 
     1248                        } 
     1249                        /* END fmbiete's contribution r1528, ZP-320 */ 
    10761250                    } 
    1077  
    10781251                } 
    10791252            } 
     
    10811254            unset($mobj); 
    10821255            unset($mail); 
    1083  
    1084             $output->body .= ' '; //Adicionado pois por algum motivo o android corta o ultimo caractere ao fazer a operação maiores detalhes 
    10851256            return $output; 
    1086  
    10871257        } 
    10881258 
     
    11001270     */ 
    11011271    public function StatMessage($folderid, $id) { 
    1102         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->StatMessage('%s','%s')", $folderid,  $id)); 
     1272        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->StatMessage('%s','%s')", $folderid,  $id)); 
    11031273        $folderImapid = $this->getImapIdFromFolderId($folderid); 
    11041274 
     
    11071277 
    11081278        if (!$overview) { 
    1109             ZLog::Write(LOGLEVEL_WARN, sprintf("ExpressoImapProvider->StatMessage('%s','%s'): Failed to retrieve overview: %s", $folderid,  $id, imap_last_error())); 
     1279            ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->StatMessage('%s','%s'): Failed to retrieve overview: %s", $folderid,  $id, imap_last_error())); 
    11101280            return false; 
    11111281        } 
     
    11311301    /** 
    11321302     * Called when a message has been changed on the mobile. 
    1133      * This functionality is not available for emails. 
     1303     * Added support for FollowUp flag 
    11341304     * 
    11351305     * @param string        $folderid       id of the folder 
     
    11421312     */ 
    11431313    public function ChangeMessage($folderid, $id, $message) { 
    1144         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->ChangeMessage('%s','%s','%s')", $folderid, $id, get_class($message))); 
    1145         // TODO recheck implementation 
    1146         // TODO this could throw several StatusExceptions like e.g. SYNC_STATUS_OBJECTNOTFOUND, SYNC_STATUS_SYNCCANNOTBECOMPLETED 
    1147         return false; 
     1314        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->ChangeMessage('%s','%s','%s')", $folderid, $id, get_class($message))); 
     1315 
     1316        /* BEGIN fmbiete's contribution r1529, ZP-321 */ 
     1317        if (isset($message->flag)) { 
     1318            ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->ChangeMessage('Setting flag')")); 
     1319 
     1320            $folderImapid = $this->getImapIdFromFolderId($folderid); 
     1321 
     1322            $this->imap_reopenFolder($folderImapid); 
     1323 
     1324            if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) { 
     1325                ZLog::Write(LOGLEVEL_DEBUG, "Set On FollowUp -> IMAP Flagged"); 
     1326                $status = @imap_setflag_full($this->mbox, $id, "\\Flagged",ST_UID); 
     1327            } 
     1328            else { 
     1329                ZLog::Write(LOGLEVEL_DEBUG, "Clearing Flagged"); 
     1330                $status = @imap_clearflag_full ( $this->mbox, $id, "\\Flagged", ST_UID); 
     1331            } 
     1332 
     1333            if ($status) { 
     1334                ZLog::Write(LOGLEVEL_DEBUG, "Flagged changed"); 
     1335            } 
     1336            else { 
     1337                ZLog::Write(LOGLEVEL_DEBUG, "Flagged failed"); 
     1338            } 
     1339        } 
     1340 
     1341        return $this->StatMessage($folderid, $id); 
     1342        /* END fmbiete's contribution r1529, ZP-321 */ 
    11481343    } 
    11491344 
     
    11601355     */ 
    11611356    public function SetReadFlag($folderid, $id, $flags) { 
    1162         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->SetReadFlag('%s','%s','%s')", $folderid, $id, $flags)); 
     1357        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->SetReadFlag('%s','%s','%s')", $folderid, $id, $flags)); 
    11631358        $folderImapid = $this->getImapIdFromFolderId($folderid); 
    11641359 
     
    11871382     */ 
    11881383    public function DeleteMessage($folderid, $id) { 
    1189         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->DeleteMessage('%s','%s')", $folderid, $id)); 
     1384        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->DeleteMessage('%s','%s')", $folderid, $id)); 
    11901385        $folderImapid = $this->getImapIdFromFolderId($folderid); 
    11911386 
     
    11951390        $s2 = @imap_expunge($this->mbox); 
    11961391 
    1197         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->DeleteMessage('%s','%s'): result: s-delete: '%s' s-expunge: '%s' setflag: '%s'", $folderid, $id, $s1, $s2, $s11)); 
     1392        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->DeleteMessage('%s','%s'): result: s-delete: '%s' s-expunge: '%s' setflag: '%s'", $folderid, $id, $s1, $s2, $s11)); 
    11981393 
    11991394        return ($s1 && $s2 && $s11); 
     
    12121407     */ 
    12131408    public function MoveMessage($folderid, $id, $newfolderid) { 
    1214         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->MoveMessage('%s','%s','%s')", $folderid, $id, $newfolderid)); 
     1409        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->MoveMessage('%s','%s','%s')", $folderid, $id, $newfolderid)); 
    12151410        $folderImapid = $this->getImapIdFromFolderId($folderid); 
    12161411        $newfolderImapid = $this->getImapIdFromFolderId($newfolderid); 
     
    12251420 
    12261421        if (!$overview) 
    1227             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); 
     1422            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); 
    12281423        else { 
    12291424            // get next UID for destination folder 
     
    12341429            $destStatus = imap_status($this->mbox, $this->server . $newfolderImapid, SA_ALL); 
    12351430            if (!$destStatus) 
    1236                 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); 
     1431                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); 
    12371432 
    12381433            $newid = $destStatus->uidnext; 
     
    12411436            $s1 = imap_mail_move($this->mbox, $id, $newfolderImapid, CP_UID); 
    12421437            if (! $s1) 
    1243                 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); 
     1438                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); 
    12441439 
    12451440 
     
    12501445            $stat = $this->imap_reopenFolder($newfolderImapid); 
    12511446            if (! $s1) 
    1252                 throw new StatusException(sprintf("ExpressoImapProvider->MoveMessage('%s','%s','%s'): Error, openeing the destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE); 
     1447                throw new StatusException(sprintf("BackendIMAP->MoveMessage('%s','%s','%s'): Error, openeing the destination folder: %s", $folderid, $id, $newfolderid, imap_last_error()), SYNC_MOVEITEMSSTATUS_CANNOTMOVE); 
    12531448 
    12541449 
     
    12611456            $s4 = @imap_setflag_full ($this->mbox, $newid, $newflags, FT_UID); 
    12621457 
    1263             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))); 
     1458            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))); 
    12641459 
    12651460            // return the new id "as string"" 
     
    12871482            if (isset($this->permanentStorage->fmFidFimap[$folderid])) { 
    12881483                $imapId = $this->permanentStorage->fmFidFimap[$folderid]; 
    1289                 ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->getImapIdFromFolderId('%s') = %s", $folderid, $imapId)); 
     1484                ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getImapIdFromFolderId('%s') = %s", $folderid, $imapId)); 
    12901485                return $imapId; 
    12911486            } 
    12921487            else { 
    1293                 ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->getImapIdFromFolderId('%s') = %s", $folderid, 'not found')); 
     1488                ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getImapIdFromFolderId('%s') = %s", $folderid, 'not found')); 
    12941489                return false; 
    12951490            } 
    12961491        } 
    1297         ZLog::Write(LOGLEVEL_WARN, sprintf("ExpressoImapProvider->getImapIdFromFolderId('%s') = %s", $folderid, 'not initialized!')); 
     1492        ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->getImapIdFromFolderId('%s') = %s", $folderid, 'not initialized!')); 
    12981493        return false; 
    12991494    } 
     
    13131508            if (isset($this->permanentStorage->fmFimapFid[$imapid])) { 
    13141509                $folderid = $this->permanentStorage->fmFimapFid[$imapid]; 
    1315                 ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->getFolderIdFromImapId('%s') = %s", $imapid, $folderid)); 
     1510                ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getFolderIdFromImapId('%s') = %s", $imapid, $folderid)); 
    13161511                return $folderid; 
    13171512            } 
    13181513            else { 
    1319                 ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->getFolderIdFromImapId('%s') = %s", $imapid, 'not found')); 
     1514                ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->getFolderIdFromImapId('%s') = %s", $imapid, 'not found')); 
    13201515                return false; 
    13211516            } 
    13221517        } 
    1323         ZLog::Write(LOGLEVEL_WARN, sprintf("ExpressoImapProvider->getFolderIdFromImapId('%s') = %s", $imapid, 'not initialized!')); 
     1518        ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->getFolderIdFromImapId('%s') = %s", $imapid, 'not initialized!')); 
    13241519        return false; 
    13251520    } 
     
    13631558        } 
    13641559 
    1365         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExpressoImapProvider->convertImapId('%s') = %s", $imapid, $folderid)); 
     1560        ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->convertImapId('%s') = %s", $imapid, $folderid)); 
    13661561 
    13671562        return $folderid; 
     
    13851580        if($body === "") { 
    13861581            $this->getBodyRecursive($message, "html", $body); 
    1387             // remove css-style tags 
    1388             $body = preg_replace("/<style.*?<\/style>/is", "", $body); 
    1389             // remove all other html 
    1390             $body = strip_tags($body); 
    13911582        } 
    13921583 
     
    14261617     */ 
    14271618    protected function getServerDelimiter() { 
    1428         $list = @imap_getmailboxes($this->mbox, $this->server, "*"); 
     1619        $list = @imap_getmailboxes($this->mbox, $this->server, "INBOX*"); 
    14291620        if (is_array($list)) { 
    14301621            $val = $list[0]; 
     
    14471638    protected function imap_reopenFolder($folderid, $force = false) { 
    14481639        // to see changes, the folder has to be reopened! 
    1449         if ($this->mboxFolder != $folderid || $force) { 
    1450             $s = @imap_reopen($this->mbox, $this->server . $folderid); 
    1451             // TODO throw status exception 
    1452             if (!$s) { 
    1453                 ZLog::Write(LOGLEVEL_WARN, "ExpressoImapProvider->imap_reopenFolder('%s'): failed to change folder: ",$folderid, implode(", ", imap_errors())); 
     1640           if ($this->mboxFolder != $folderid || $force) { 
     1641               $s = @imap_reopen($this->mbox, $this->server . $folderid); 
     1642               // TODO throw status exception 
     1643               if (!$s) { 
     1644                ZLog::Write(LOGLEVEL_WARN, "BackendIMAP->imap_reopenFolder('%s'): failed to change folder: ",$folderid, implode(", ", imap_errors())); 
    14541645                return false; 
    1455             } 
     1646               } 
    14561647            $this->mboxFolder = $folderid; 
    14571648        } 
     
    15641755            foreach($ad as $addr) { 
    15651756                if ($addr_string) $addr_string .= ","; 
    1566                 $addr_string .= $addr->mailbox . "@" . $addr->host; 
     1757                    $addr_string .= $addr->mailbox . "@" . $addr->host; 
    15671758            } 
    15681759        } 
     
    16271818    } 
    16281819 
    1629 } 
     1820    /* BEGIN fmbiete's contribution r1528, ZP-320 */ 
     1821    /** 
     1822     * Indicates which AS version is supported by the backend. 
     1823     * 
     1824     * @access public 
     1825     * @return string       AS version constant 
     1826     */ 
     1827    public function GetSupportedASVersion() { 
     1828        return ZPush::ASV_14; 
     1829    } 
     1830    /* END fmbiete's contribution r1528, ZP-320 */ 
     1831}; 
    16301832 
    16311833?> 
  • trunk/zpush/lib/request/sync.php

    r7589 r7671  
    708708                                $spa->SetNewSyncKey(self::$deviceManager->GetStateManager()->GetNewSyncKey($spa->GetSyncKey())); 
    709709 
     710                        self::$encoder->startTag(SYNC_FOLDER); 
     711 
    710712                        if($spa->HasContentClass()) { 
    711713                            ZLog::Write(LOGLEVEL_DEBUG, sprintf("Folder type: %s", $spa->GetContentClass())); 
    712                         } 
    713  
    714                         self::$encoder->startTag(SYNC_FOLDER); 
     714                            // AS 12.0 devices require content class 
     715                            if (Request::GetProtocolVersion() < 12.1) { 
     716                                self::$encoder->startTag(SYNC_FOLDERTYPE); 
     717                                self::$encoder->content($spa->GetContentClass()); 
     718                                self::$encoder->endTag(); 
     719                            } 
     720                        } 
    715721 
    716722                        self::$encoder->startTag(SYNC_SYNCKEY); 
Note: See TracChangeset for help on using the changeset viewer.