Make sure the correct identity is used for list command mailto actions
[squirrelmail.git] / plugins / listcommands / functions.php
index 6c526c2a49ff4e72a6aa03293cb85ca8dea6bd07..63fa24c6acb0f76c0117e29ea88b3ad05d297200 100644 (file)
@@ -90,20 +90,39 @@ function plugin_listcommands_menu_do() {
 
         if ($proto == 'mailto') {
 
+            $identity = '';
+
             if (($cmd == 'post') || ($cmd == 'owner')) {
                 $url = 'src/compose.php?'.
                     (isset($startMessage)?'startMessage='.$startMessage.'&':'');
             } else {
                 $url = "plugins/listcommands/mailout.php?action=$cmd&";
+
+                // try to find which identity the mail should come from
+                include_once(SM_PATH . 'functions/identity.php');
+                $idents = get_identities();
+                // ripped from src/compose.php
+                $identities = array();
+                if (count($idents) > 1) {
+                    foreach($idents as $nr=>$data) {
+                        $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
+                        $identities[] = $enc_from_name;
+                    }
+
+                    $identity_match = $message->rfc822_header->findAddress($identities);
+                    if ($identity_match !== FALSE) {
+                        $identity = $identity_match;
+                    }
+                }
             }
 
             // if things like subject are given, peel them off and give
             // them to src/compose.php as is (not encoded)
             if (strpos($act, '?') > 0) {
                list($act, $parameters) = explode('?', $act, 2);
-               $parameters = '&amp;' . $parameters;
+               $parameters = '&amp;identity=' . $identity . '&amp;' . $parameters;
             } else {
-               $parameters = '';
+               $parameters = '&amp;identity=' . $identity;
             }
 
             $url .= 'send_to=' . urlencode($act) . $parameters;