[dev] [PATCH] Default BCC for each identity?

Nicholas Sushkin nsushkin at users.sourceforge.net
Tue Nov 11 07:36:33 PST 2003


Here's a patch to IMP HEAD branch that allows to have initial values of
the BCC header for each identity. This is a feature that I frequently use
in KDE KMail that I really miss in IMP.

Basically, I added a field 'bcc_addr' to the identity object. The new
field contains a list of bcc addresses. When you compose a message,
your BCC: header would be automatically initialized from the bcc_addr
identity field. If you switch your identity in the compose window,
the bcc addresses from the new identity will override the current value
of the BCC: header.

I tried to follow the coding conventions as close as possible.

Hope to see this incorporated into the code. Thanks.

Nick
------------------ Original Message -------------------------------
From: Michael M Slusarz <slusarz at bigworm.colorado.edu>

Quoting Nicholas Sushkin <nsushkin at sushkins.net>:

| There is a feature that KMail has that I really miss in IMP that I use
| when I can't access my desktop.
|
| In KMail, each identity can have an optional list of BCC addresses.
| So that some in addition to FCC, identities automatically BCC all
| outgoing email
| to the specified email addresses.
|
| Could you please consider this feature for the next release.

Sure, if someone wants to write a patch.

michael

______________________________________________
Michael Slusarz [slusarz at bigworm.colorado.edu]
The University of Colorado at Boulder
-------------- next part --------------
? imp-bcc-add.patch
Index: compose.php
===================================================================
RCS file: /repository/imp/compose.php,v
retrieving revision 2.690
diff -u -3 -p -r2.690 compose.php
--- compose.php	23 Oct 2003 19:12:43 -0000	2.690
+++ compose.php	8 Nov 2003 13:38:43 -0000
@@ -297,6 +297,10 @@ $smime_passphrase_dialog = false;
 
 $identity = &Identity::singleton(array('imp', 'imp'));
 $sent_mail_folder = $identity->getValue('sent_mail_folder', Util::getFormData('identity'));
+$bcc_addr = $identity->getBccAddresses();
+/* Build the Bcc: header. */
+$header['bcc'] = MIME::addrArray2String($bcc_addr);
+
 $actionID = Util::getFormData('actionID');
 if (($index = Util::getFormData('index'))) {
     $imp_contents = &new IMP_Contents($index);
@@ -450,7 +454,7 @@ case 'reply_list':
             $header['cc'] = MIME::addrArray2String($cc_arr, array_merge($me, IMP::bareAddress($header['to'])));
 
             /* Build the Bcc: header. */
-            $header['bcc'] = MIME::addrArray2String($imp_headers->getOb('bcc'), $me);
+            $header['bcc'] = MIME::addrArray2String($imp_headers->getOb('bcc'), $me, $bcc_addr);
         } elseif ($actionID == 'reply_list') {
             $header['to'] = Util::getFormData('to');
         }
@@ -1123,9 +1127,11 @@ foreach ($all_sigs as $ident => $sig) {
     $identities[$ident] = array($sig,
                                 $identity->getValue('sig_first', $ident),
                                 $select,
-                                $identity->getValue('save_sent_mail', $ident));
+                                $identity->getValue('save_sent_mail', $ident),
+                                MIME::addrArray2String($identity->getBccAddresses($ident)));
 }
 $sig = $identity->getSignature();
+
 
 if ($get_sig && isset($msg) && !empty($sig)) {
     if ($identity->getValue('sig_first')) {
Index: identities.php
===================================================================
RCS file: /repository/imp/identities.php,v
retrieving revision 2.56
diff -u -3 -p -r2.56 identities.php
--- identities.php	28 Oct 2003 21:24:33 -0000	2.56
+++ identities.php	8 Nov 2003 13:38:43 -0000
@@ -89,6 +89,13 @@ case 'ident_save':
         $data = (empty($data)) ? array() : Horde_Array::prepareAddressList(preg_split("/\s+/", $data));
         $identity->setValue($val, $data);
     }
+    
+    foreach (array('bcc_addr') as $val) {
+        $data = Util::getFormData($val);
+        $data = trim($data);
+        $data = (empty($data)) ? array() : preg_split("/[\r\n]+/", $data);
+        $identity->setValue($val, $data);
+    }
 
     $identity->setValue('signature', Util::getFormData('signature'));
     $identity->setValue('sig_dashes', Util::getFormData('sig_dashes', 0));
Index: config/prefs.php.dist
===================================================================
RCS file: /repository/imp/config/prefs.php.dist,v
retrieving revision 1.179
diff -u -3 -p -r1.179 prefs.php.dist
--- config/prefs.php.dist	16 Oct 2003 17:57:57 -0000	1.179
+++ config/prefs.php.dist	8 Nov 2003 13:38:43 -0000
@@ -259,6 +259,13 @@ $_prefs['tieto_addr'] = array(
     'shared' => true,
     'type' => 'implicit');
 
+// additional BCC: addresses
+$_prefs['bcc_addr'] = array(
+    'value' => '',
+    'locked' => false,
+    'shared' => true,
+    'type' => 'implicit');
+
 // save a copy of sent messages?
 // a value of 0 = no, 1 = yes
 $_prefs['save_sent_mail'] = array(
Index: lib/Identity/imp.php
===================================================================
RCS file: /repository/imp/lib/Identity/imp.php,v
retrieving revision 1.26
diff -u -3 -p -r1.26 imp.php
--- lib/Identity/imp.php	23 Oct 2003 09:39:35 -0000	1.26
+++ lib/Identity/imp.php	8 Nov 2003 13:38:43 -0000
@@ -30,7 +30,7 @@ class Identity_imp extends Identity {
      * @var array $_properties
      */
     var $_properties = array(
-        'fullname', 'from_addr', 'replyto_addr', 'alias_addr', 'tieto_addr',
+        'fullname', 'from_addr', 'replyto_addr', 'alias_addr', 'tieto_addr', 'bcc_addr',
         'signature', 'sig_first', 'sig_dashes', 'save_sent_mail',
         'sent_mail_folder'
     );
@@ -282,6 +282,22 @@ class Identity_imp extends Identity {
 
         return $list;
     }
+
+    /**
+     * Returns the BCC addresses.
+     *
+     * @param optional integer $ident  The identity to retrieve the bcc addresses
+     *                                 from.
+     *
+     * @return array of objects  The array of objects (IMAP addresses)
+     */
+    function getBccAddresses($ident = null)
+    {
+        $addresses = implode(', ', $this->getValue('bcc_addr', $ident));
+        $addresses = imap_rfc822_parse_adrlist($addresses, '');
+        return $addresses;
+    }
+    
 
     /**
      * Returns the identity's id that matches the passed addresses.
Index: templates/compose/compose.js
===================================================================
RCS file: /repository/imp/templates/compose/compose.js,v
retrieving revision 2.11
diff -u -3 -p -r2.11 compose.js
--- templates/compose/compose.js	24 Oct 2003 21:06:31 -0000	2.11
+++ templates/compose/compose.js	8 Nov 2003 13:38:44 -0000
@@ -50,12 +50,20 @@ foreach ($identities as $ident) {
         $js .= 'null)';
     } else {
         if (isset($ident[2])) {
-            $js .= '"\"' . IMP::displayFolder($ident[2]) . '\"")';
+            $js .= '"\"' . IMP::displayFolder($ident[2]) . '\""';
         } else {
-            $js .= '"")';
+            $js .= '""';
         }
     }
-    $js .= ",\n";
+    $js .= ", ";
+
+    if (isset($ident[4])) {
+        $js .= '"' . $ident[4] . '"';
+    } else {
+        $js .= '""';
+    }
+
+    $js .= "),\n";
 }
 $js = substr($js, 0, -2) . "\n";
 echo $js;
@@ -117,6 +125,9 @@ function change_identity(id)
 <?php endif; ?>
     if (document.compose.save_sent_mail) {
         document.compose.save_sent_mail.checked = next[3];
+    }
+    if (document.compose.bcc) {
+        document.compose.bcc.value = next[5];
     }
 }
 
Index: templates/identities/javascript.inc
===================================================================
RCS file: /repository/imp/templates/identities/javascript.inc,v
retrieving revision 1.23
diff -u -3 -p -r1.23 javascript.inc
--- templates/identities/javascript.inc	1 Aug 2003 21:24:08 -0000	1.23
+++ templates/identities/javascript.inc	8 Nov 2003 13:38:44 -0000
@@ -10,6 +10,7 @@ var fields = new Array(
     $folder = (empty($folder)) ? '' : IMP::preambleString() . $folder;
     $aliasaddr = $identity->getValue('alias_addr', $i);
     $tietoaddr = $identity->getValue('tieto_addr', $i);
+    $bccaddr = $identity->getValue('bcc_addr', $i);
 ?>
     new Array(
         "<?php echo addslashes($identity->getValue('id', $i)) ?>",
@@ -18,6 +19,7 @@ var fields = new Array(
         "<?php echo addslashes($identity->getValue('replyto_addr', $i)) ?>",
         "<?php echo (empty($aliasaddr)) ? '' : str_replace("\n", '\n', addslashes(@implode("\n", $aliasaddr))) ?>",
         "<?php echo (empty($tietoaddr)) ? '' : str_replace("\n", '\n', addslashes(implode("\n", $tietoaddr))) ?>",
+        "<?php echo (empty($bccaddr)) ? '' : str_replace("\n", '\n', addslashes(implode("\n", $bccaddr))) ?>",
         "<?php echo str_replace("\r", '', str_replace("\n", '\n', addslashes($identity->getValue('signature', $i)))) ?>",
         "<?php echo addslashes($identity->getValue('sig_dashes', $i)) ?>",
         "<?php echo addslashes($identity->getValue('sig_first', $i)) ?>",
@@ -62,25 +64,28 @@ function updateForm(identity)
 <?php if (!$prefs->isLocked('tieto_addr')): ?>
     document.identities.tieto_addr.value = fields[identity][5];
 <?php endif; ?>
+<?php if (!$prefs->isLocked('bcc_addr')): ?>
+    document.identities.bcc_addr.value = fields[identity][6];
+<?php endif; ?>
 <?php if (!$prefs->isLocked('signature')): ?>
-    document.identities.signature.value = fields[identity][6];
+    document.identities.signature.value = fields[identity][7];
 <?php endif; ?>
 <?php if (!$prefs->isLocked('sig_dashes')): ?>
-    if (fields[identity][7] == "1") document.identities.sig_dashes.checked = true;
+    if (fields[identity][8] == "1") document.identities.sig_dashes.checked = true;
     else document.identities.sig_dashes.checked = false;
 <?php endif; ?>
 <?php if (!$prefs->isLocked('sig_first')): ?>
-    if (fields[identity][8] == "1") document.identities.sig_first.checked = true;
+    if (fields[identity][9] == "1") document.identities.sig_first.checked = true;
     else document.identities.sig_first.checked = false;
 <?php endif; ?>
 <?php if (!$prefs->isLocked('save_sent_mail')): ?>
-    if (fields[identity][9] == "1") document.identities.save_sent_mail.checked = true;
+    if (fields[identity][10] == "1") document.identities.save_sent_mail.checked = true;
     else document.identities.save_sent_mail.checked = false;
 <?php endif; ?>
 <?php if (!$prefs->isLocked('sent_mail_folder')): ?>
     document.identities.sent_mail.selectedIndex = 0;
     for (var i = 0; i < document.identities.sent_mail.length; i++) {
-        if (document.identities.sent_mail[i].value == fields[identity][10]) {
+        if (document.identities.sent_mail[i].value == fields[identity][11]) {
             document.identities.sent_mail.selectedIndex = i;
             break;
         }
@@ -108,6 +113,9 @@ function clearForm()
 <?php endif; ?>
 <?php if (!$prefs->isLocked('tieto_addr')): ?>
     document.identities.tieto_addr.value = '';
+<?php endif; ?>
+<?php if (!$prefs->isLocked('bcc_addr')): ?>
+    document.identities.bcc_addr.value = '';
 <?php endif; ?>
 <?php if (!$prefs->isLocked('signature')): ?>
     document.identities.signature.value = '';
Index: templates/identities/manage.inc
===================================================================
RCS file: /repository/imp/templates/identities/manage.inc,v
retrieving revision 1.31
diff -u -3 -p -r1.31 manage.inc
--- templates/identities/manage.inc	16 Sep 2003 23:05:18 -0000	1.31
+++ templates/identities/manage.inc	8 Nov 2003 13:38:44 -0000
@@ -62,22 +62,27 @@
 
 <?php if (!$prefs->isLocked('from_addr')): ?>
             <?php echo Horde::label('from_addr', _("Your From: address:")) ?><br />
-            <input name="from_addr" id="from_addr" size="30" maxlength="60" class="fixed" <?php if (isset($to_edit)) echo 'value="' . $identity->getValue('from_addr', $to_edit) . '" '; ?>/><br />
+            <input name="from_addr" id="from_addr" size="50" maxlength="60" class="fixed" <?php if (isset($to_edit)) echo 'value="' . $identity->getValue('from_addr', $to_edit) . '" '; ?>/><br />
 <?php endif; ?>
 
 <?php if (!$prefs->isLocked('replyto_addr')): ?>
             <?php echo Horde::label('replyto_addr', _("Your Reply-to: address: <i>(optional)</i>")) ?><br />
-            <input name="replyto_addr" id="replyto_addr" size="30" maxlength="60" class="fixed" <?php if (isset($to_edit)) echo 'value="' . $identity->getValue('replyto_addr', $to_edit) . '" '; ?>/><br />
+            <input name="replyto_addr" id="replyto_addr" size="50" maxlength="60" class="fixed" <?php if (isset($to_edit)) echo 'value="' . $identity->getValue('replyto_addr', $to_edit) . '" '; ?>/><br />
 <?php endif; ?>
 
 <?php if (!$prefs->isLocked('alias_addr')): ?>
             <?php echo Horde::label('alias_addr', _("Your alias addresses: <i>(optional, enter each address on new line)</i>")) ?><br />
-            <textarea name="alias_addr" id="alias_addr" rows="3" cols="40" class="fixed"><?php if (isset($to_edit)) echo implode("\n", $identity->getValue('alias_addr', $to_edit)) ?></textarea><br />
+            <textarea name="alias_addr" id="alias_addr" rows="3" cols="50" class="fixed"><?php if (isset($to_edit)) echo implode("\n", $identity->getValue('alias_addr', $to_edit)) ?></textarea><br />
 <?php endif; ?>
 
 <?php if (!$prefs->isLocked('tieto_addr')): ?>
             <?php echo Horde::label('tieto_addr', _("Addresses to explicitly tie to this identity: <i>(optional, enter each address on new line)</i>")) ?><br />
-            <textarea name="tieto_addr" id="tieto_addr" rows="3" cols="40" class="fixed"><?php if (isset($to_edit)) echo implode("\n", $identity->getValue('tieto_addr', $to_edit)) ?></textarea><br />
+            <textarea name="tieto_addr" id="tieto_addr" rows="3" cols="50" class="fixed"><?php if (isset($to_edit)) echo implode("\n", $identity->getValue('tieto_addr', $to_edit)) ?></textarea><br />
+<?php endif; ?>
+
+<?php if (!$prefs->isLocked('bcc_addr')): ?>
+            <?php echo Horde::label('bcc_addr', _("Your additional BCC: addresses: <i>(optional, enter each address on new line)</i>")) ?><br />
+            <textarea name="bcc_addr" id="bcc_addr" rows="3" cols="50" class="fixed"><?php if (isset($to_edit)) echo implode("\n", $identity->getValue('bcc_addr', $to_edit)) ?></textarea><br />
 <?php endif; ?>
 
 <?php if (!$prefs->isLocked('signature')): ?>


More information about the dev mailing list