Browse Source

Suggesting senders address if none is present in the vCard

Fredrik Jervfors 21 years ago
parent
commit
92e3b26a9e
5 changed files with 42 additions and 13 deletions
  1. 2 2
      ChangeLog
  2. 1 1
      functions/attachment_common.php
  3. 26 1
      functions/url_parser.php
  4. 2 2
      po/squirrelmail.pot
  5. 11 7
      src/vcard.php

+ 2 - 2
ChangeLog

@@ -114,9 +114,9 @@ Version 1.5.1 -- CVS
     See plugins/fortune/INSTALL.
     See plugins/fortune/INSTALL.
   - Fix for #906217 when checking spelling of inline replies, the corrected
   - Fix for #906217 when checking spelling of inline replies, the corrected
     words would appear through original email.
     words would appear through original email.
-  - Fixed empty information menu when viewing vcards without information
+  - Fixed empty information menu when viewing vCards without information
     but name and e-mail address.
     but name and e-mail address.
-  - User may now add an e-mail address when adding vcards without one to the
+  - User may now add an e-mail address when adding vCards without one to the
     address book. No need to wait for the error message anymore.
     address book. No need to wait for the error message anymore.
   - Removed japanese_xtra function used by older XTRA_CODE calls. Plugins
   - Removed japanese_xtra function used by older XTRA_CODE calls. Plugins
     should use separate xtra_code functions. Older function does not provide
     should use separate xtra_code functions. Older function does not provide

+ 1 - 1
functions/attachment_common.php

@@ -175,7 +175,7 @@ function attachment_common_link_vcard(&$Args) {
           set_url_var($Args[1]['attachment_common']['href'],
           set_url_var($Args[1]['attachment_common']['href'],
           'ent_id',$Args[5]);
           'ent_id',$Args[5]);
 
 
-    $Args[1]['attachment_common']['text'] = _("Business Card");
+    $Args[1]['attachment_common']['text'] = _("View business Card");
 
 
     $Args[6] = $Args[1]['attachment_common']['href'];
     $Args[6] = $Args[1]['attachment_common']['href'];
 }
 }

+ 26 - 1
functions/url_parser.php

@@ -51,7 +51,7 @@ $Email_RegExp_Match = $dot_atom . '(%' . $Host_RegExp_Match . ')?@' .
  * @return int the number of unique addresses found
  * @return int the number of unique addresses found
  */
  */
 function parseEmail (&$body) {
 function parseEmail (&$body) {
-    global $color, $Email_RegExp_Match;
+    global $Email_RegExp_Match;
     $sbody     = $body;
     $sbody     = $body;
     $addresses = array();
     $addresses = array();
 
 
@@ -61,11 +61,13 @@ function parseEmail (&$body) {
         $start = strpos($sbody, $regs[0]) + strlen($regs[0]);
         $start = strpos($sbody, $regs[0]) + strlen($regs[0]);
         $sbody = substr($sbody, $start);
         $sbody = substr($sbody, $start);
     }
     }
+
     /* Replace each email address with a compose URL */
     /* Replace each email address with a compose URL */
     foreach ($addresses as $text => $email) {
     foreach ($addresses as $text => $email) {
         $comp_uri = makeComposeLink('src/compose.php?send_to='.urlencode($email), $text);
         $comp_uri = makeComposeLink('src/compose.php?send_to='.urlencode($email), $text);
         $body = str_replace($text, $comp_uri, $body);
         $body = str_replace($text, $comp_uri, $body);
     }
     }
+
     /* Return number of unique addresses found */
     /* Return number of unique addresses found */
     return count($addresses);
     return count($addresses);
 }
 }
@@ -198,4 +200,27 @@ function parseUrl (&$body) {
         $blength = strlen($body);
         $blength = strlen($body);
     }
     }
 }
 }
+
+/**
+ * Parses a string and returns the first e-mail address found.
+ *
+ * @param string string the string to process
+ * @return string the first e-mail address found
+ */
+function getEmail($string) {
+    global $Email_RegExp_Match;
+    $addresses = array();
+
+    /* Find all the email addresses in the body */
+    while (eregi($Email_RegExp_Match, $string, $regs)) {
+        $addresses[$regs[0]] = strtr($regs[0], array('&' => '&'));
+       	$start = strpos($string, $regs[0]) + strlen($regs[0]);
+       	$string = substr($string, $start);
+    }
+
+    /* Return the first address, or an empty string if no address was found */
+    $addresses = array_values($addresses);
+    return (array_key_exists(0, $addresses) ? $addresses[0] : '');
+}
+
 ?>
 ?>

+ 2 - 2
po/squirrelmail.pot

@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2004-10-24 23:13+0200\n"
+"POT-Creation-Date: 2004-10-26 07:22+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -1059,7 +1059,7 @@ msgstr ""
 msgid "View"
 msgid "View"
 msgstr ""
 msgstr ""
 
 
-msgid "Business Card"
+msgid "View business Card"
 msgstr ""
 msgstr ""
 
 
 msgid "Sunday"
 msgid "Sunday"

+ 11 - 7
src/vcard.php

@@ -21,6 +21,7 @@ Define('SM_PATH','../');
 /* SquirrelMail required files. */
 /* SquirrelMail required files. */
 require_once(SM_PATH . 'include/validate.php');
 require_once(SM_PATH . 'include/validate.php');
 require_once(SM_PATH . 'functions/mime.php');
 require_once(SM_PATH . 'functions/mime.php');
+require_once(SM_PATH . 'functions/url_parser.php');
 
 
 /* globals */
 /* globals */
 sqgetGlobalVar('username', $username, SQ_SESSION);
 sqgetGlobalVar('username', $username, SQ_SESSION);
@@ -153,19 +154,22 @@ echo addInput('addaddr[nickname]', $vcard_safe['firstname'] .
         '-' . $vcard_safe['lastname'], '20');
         '-' . $vcard_safe['lastname'], '20');
 
 
 /*
 /*
- * If the vcard comes with an e-mail address it should be added to the
+ * If the vCard comes with an e-mail address it should be added to the
  * address book, otherwise the user must add one manually to avoid an
  * address book, otherwise the user must add one manually to avoid an
- * error message in src/addressbook.php.
- *
- * TODO: If there's no e-mail address in the vcard, use the sender's address
- * instead of letting the user entering it manually.
+ * error message in src/addressbook.php. SquirrelMail is nice enough to
+ * suggest the e-mail address of the sender though.
  */
  */
 if (isset($vcard_nice['email;internet'])) {
 if (isset($vcard_nice['email;internet'])) {
     echo addHidden('addaddr[email]', $vcard_nice['email;internet']);
     echo addHidden('addaddr[email]', $vcard_nice['email;internet']);
 } else {
 } else {
+    $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
+    $header = $message->rfc822_header;
+    $from_name = $header->getAddr_s('from');
+
     echo '</td></tr>' .
     echo '</td></tr>' .
          '<tr><td align="right"><b>' . _("E-mail address") . ':</b></td><td>' .
          '<tr><td align="right"><b>' . _("E-mail address") . ':</b></td><td>' .
-         addInput('addaddr[email]', '', '20');
+         addInput('addaddr[email]',
+                 getEmail(decodeHeader($from_name)), '20');
 }
 }
 
 
 echo '</td></tr>' .
 echo '</td></tr>' .
@@ -239,4 +243,4 @@ echo '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
 <table border="0" cellspacing="0" cellpadding="2" align="center">
 <table border="0" cellspacing="0" cellpadding="2" align="center">
 <tr><td bgcolor="<?php echo $color[4]; ?>">
 <tr><td bgcolor="<?php echo $color[4]; ?>">
 </td></tr></table>
 </td></tr></table>
-</body></html>
+</body></html>