header might have multiple user-agent rows
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 18 Jan 2016 11:31:30 +0000 (12:31 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 26 Jan 2016 19:03:57 +0000 (20:03 +0100)
* and fixes custom flag handling (flags property might be empty / not set)

Change-Id: Ieac6b838bfbd69e4bef67bd288370d65876e6cf9
Reviewed-on: http://gerrit.tine20.com/customers/2589
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Felamimail/Controller/Message/Flags.php

index 5877456..47b9dde 100644 (file)
@@ -211,7 +211,7 @@ class Felamimail_Controller_Message_Flags extends Felamimail_Controller_Message
     /**
      * returns supported flags
      * 
-     * @param boolean translated
+     * @param boolean $_translated
      * @return array
      * 
      * @todo add gettext for flags
@@ -354,11 +354,14 @@ class Felamimail_Controller_Message_Flags extends Felamimail_Controller_Message
     public function tine20FlagEnabled($message = null)
     {
         if (Felamimail_Config::getInstance()->featureEnabled(Felamimail_Config::FEATURE_TINE20_FLAG)) {
-            if ($message) {
-                return (isset($message['header']['user-agent']) && strpos( (string) $message['header']['user-agent'], "Tine 2.0") !== false);
+            if ($message && isset($message['header']['user-agent'])) {
+                $userAgentHeader = $message['header']['user-agent'];
+                foreach((array) $userAgentHeader as $userAgent) {
+                    if (strpos($userAgent, "Tine 2.0") !== false) {
+                        return true;
+                    }
+                }
             }
-
-            return true;
         }
 
         return false;
@@ -371,9 +374,12 @@ class Felamimail_Controller_Message_Flags extends Felamimail_Controller_Message
      */
     public function setTine20Flag(Felamimail_Model_Message $_message)
     {
-        if (! in_array("Tine20", $_message->flags)) {
+        $flags = isset($_message->flags) ? $_message->flags : array();
+
+        if (is_array($flags) && ! in_array("Tine20", $flags)) {
             $this->addFlags($_message->id, "Tine20");
-            $_message->flags = array("Tine20");
+            array_push($flags, "Tine20");
+            $_message->flags = $flags;
         }
     }
 }