Skip to content

ActiveSync: user flags lost and warnings per message since msgflags is unserialized with allowed_classes => false #252

Closed

Description

@dieg0nob

Versions: horde/core 3.3.0 (also current FRAMEWORK_6_0), horde/imp 7.2.0, PHP 8.3.

Problem

Horde_Core_ActiveSync_Imap_Factory::getMsgFlags() unserializes IMP's msgflags preference with ['allowed_classes' => false] (introduced in #129, ZDI-20-1051). That preference stores IMP_Flag_* objects, which therefore become __PHP_Incomplete_Class. The consequences are:

  • Two PHP warnings for every synced message:
    Class __PHP_Incomplete_Class has no unserializer
    Attempt to read property "imapflag" on __PHP_Incomplete_Class
    
    We saw ~850 warnings in 15 minutes for a single user.
  • The user's own flags (labels) never reach the ActiveSync device.

Proposed fix

Use the same class whitelist that IMP itself uses for this preference (IMP_Flags::__construct() in imp/lib/Flags.php). This allows no class that IMP does not already allow. Also return [] if the preference cannot be read, instead of iterating a non-array.

The patch is below.

--- a/lib/Horde/Core/ActiveSync/Imap/Factory.php
+++ b/lib/Horde/Core/ActiveSync/Imap/Factory.php
@@ -199,7 +199,31 @@
         global $registry;
 
         $msgFlags = [];
-        $flags = unserialize($registry->horde->getPreference($registry->hasInterface('mail'), 'msgflags'), ['allowed_classes' => false]);
+        // Same allowed classes as IMP_Flags::__construct() (imp/lib/Flags.php).
+        // With 'allowed_classes' => false the IMP_Flag_* objects become
+        // __PHP_Incomplete_Class and user flags never reach the device.
+        $flags = @unserialize($registry->horde->getPreference($registry->hasInterface('mail'), 'msgflags'), ['allowed_classes' => [
+            'IMP_Flag_User',
+            'IMP_Flag_Imap_Answered',
+            'IMP_Flag_Imap_Deleted',
+            'IMP_Flag_Imap_Draft',
+            'IMP_Flag_Imap_Flagged',
+            'IMP_Flag_Imap_Forwarded',
+            'IMP_Flag_Imap_Junk',
+            'IMP_Flag_Imap_NotJunk',
+            'IMP_Flag_Imap_Seen',
+            'IMP_Flag_System_Attachment',
+            'IMP_Flag_System_Encrypted',
+            'IMP_Flag_System_HighPriority',
+            'IMP_Flag_System_List',
+            'IMP_Flag_System_LowPriority',
+            'IMP_Flag_System_Personal',
+            'IMP_Flag_System_Signed',
+            'IMP_Flag_System_Unseen',
+        ]]);
+        if (!is_array($flags)) {
+            return [];
+        }
 
         // Remove any system flags, as these should never be user (un)set.
         $system_flags = [
@@ -215,7 +239,7 @@
         }
 
         foreach ($flags as $flag) {
-            if ($flag->imapflag) {
+            if (is_object($flag) && $flag->imapflag) {
                 $msgFlags[Horde_String::lower($flag->imapflag)] = $flag->label;
             }
         }

Activity

  1. ralflang commented on Nov 13, 2026

    @ralflang
    Member

    @TDannhauer I agree with the problem but not with the solution. Neither horde/core nor horde/activesync have any business knowing specific apps' classes.

    Either have an API method msgflags(): array (in the app's Api.php) expose a list of legit classes so we can query by capability $registry->call('mail/msgflags') or decouple the thing in another way.

  2. TDannhauer commented on Nov 13, 2026

    @TDannhauer
    Contributor

    The class list stays in IMP. Core asks the mail app for the finished map.

    Both are assigned to @ralflang. IMP should land first. Core degrades to an empty map when mail/msgflags is missing, so an older IMP keeps syncing without user labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions