From bb5d7282855dd83ccdd211cb77d0776dce71468e Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 12 Dec 2012 02:54:33 -0500
Subject: [PATCH] Use also Envelope-To for identity selection (#1488553)

---
 CHANGELOG                               |    2 +-
 program/steps/mail/compose.inc          |   10 ++++++++++
 program/lib/Roundcube/rcube_storage.php |    1 +
 3 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index ebc2796..8fd17b4 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -8,7 +8,7 @@
 - Fix broken message/part bodies when FETCH response contains more untagged lines (#1488836)
 - Fix empty email on identities list after identity update (#1488834)
 - Add new identities_level: (4) one identity with possibility to edit only signature
-- Use Delivered-To header as a last resort for identity selection (#1488840)
+- Use Delivered-To and Envelope-To headers for identity selection (#1488840, #1488553)
 - Fix XSS vulnerability using Flash files (#1488828)
 - Fix absolute positioning in HTML messages (#1488819)
 - Fix cache (in)validation after setting \Deleted flag
diff --git a/program/lib/Roundcube/rcube_storage.php b/program/lib/Roundcube/rcube_storage.php
index 245d911..7ec05b7 100644
--- a/program/lib/Roundcube/rcube_storage.php
+++ b/program/lib/Roundcube/rcube_storage.php
@@ -65,6 +65,7 @@
         'MAIL-REPLY-TO',
         'RETURN-PATH',
         'DELIVERED-TO',
+        'ENVELOPE-TO',
     );
 
     const UNKNOWN       = 0;
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index d181a72..d764f52 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -455,6 +455,16 @@
     }
   }
 
+  // Fallback using Envelope-To
+  if ($from_idx === null && ($envelope_to = $MESSAGE->headers->others['envelope-to'])) {
+    foreach ($identities as $idx => $ident) {
+      if (in_array($ident['email_ascii'], (array)$envelope_to)) {
+        $from_idx = $idx;
+        break;
+      }
+    }
+  }
+
   return $identities[$from_idx !== null ? $from_idx : $default_identity];
 }
 

--
Gitblit v1.9.1