Suggesting senders address if none is present in the vCard
authorjervfors <jervfors@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 26 Oct 2004 05:29:10 +0000 (05:29 +0000)
committerjervfors <jervfors@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 26 Oct 2004 05:29:10 +0000 (05:29 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@8250 7612ce4b-ef26-0410-bec9-ea0150e637f0

ChangeLog
functions/attachment_common.php
functions/url_parser.php
po/squirrelmail.pot
src/vcard.php

index 20d770d465e56ed55a4ee8e07bfdf4f57a545f43..37332a36b96d1a3f083bd02bada146cc849f6844 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -114,9 +114,9 @@ Version 1.5.1 -- CVS
     See plugins/fortune/INSTALL.
   - Fix for #906217 when checking spelling of inline replies, the corrected
     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.
-  - 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.
   - Removed japanese_xtra function used by older XTRA_CODE calls. Plugins
     should use separate xtra_code functions. Older function does not provide
index 3e65014fcc0918661212c0be2278e39cd4dfb51b..d0c7288e83b28603fb1149a3ea4d711d83b61154 100644 (file)
@@ -175,7 +175,7 @@ function attachment_common_link_vcard(&$Args) {
           set_url_var($Args[1]['attachment_common']['href'],
           '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'];
 }
index ca1b52d10ce155a86eecc772c24952e0ad8a9eb0..8525cc240b7ddae6db57697a980a480dc48c5bea 100644 (file)
@@ -51,7 +51,7 @@ $Email_RegExp_Match = $dot_atom . '(%' . $Host_RegExp_Match . ')?@' .
  * @return int the number of unique addresses found
  */
 function parseEmail (&$body) {
-    global $color, $Email_RegExp_Match;
+    global $Email_RegExp_Match;
     $sbody     = $body;
     $addresses = array();
 
@@ -61,11 +61,13 @@ function parseEmail (&$body) {
         $start = strpos($sbody, $regs[0]) + strlen($regs[0]);
         $sbody = substr($sbody, $start);
     }
+
     /* Replace each email address with a compose URL */
     foreach ($addresses as $text => $email) {
         $comp_uri = makeComposeLink('src/compose.php?send_to='.urlencode($email), $text);
         $body = str_replace($text, $comp_uri, $body);
     }
+
     /* Return number of unique addresses found */
     return count($addresses);
 }
@@ -198,4 +200,27 @@ function parseUrl (&$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('&amp;' => '&'));
+               $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] : '');
+}
+
 ?>
\ No newline at end of file
index 1e3cb0d22c61d1ed32e3ae58dc3bd549293ec28a..a36101ddba3866b1fd9ce0b9c7ac3e1e6124b0a8 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\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"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -1059,7 +1059,7 @@ msgstr ""
 msgid "View"
 msgstr ""
 
-msgid "Business Card"
+msgid "View business Card"
 msgstr ""
 
 msgid "Sunday"
index b3d42b10b55ec549c8145f986190df8ef184b759..b4f77e5a8f57f5f65033bf0fd5cc0503088d3450 100644 (file)
@@ -21,6 +21,7 @@ Define('SM_PATH','../');
 /* SquirrelMail required files. */
 require_once(SM_PATH . 'include/validate.php');
 require_once(SM_PATH . 'functions/mime.php');
+require_once(SM_PATH . 'functions/url_parser.php');
 
 /* globals */
 sqgetGlobalVar('username', $username, SQ_SESSION);
@@ -153,19 +154,22 @@ echo addInput('addaddr[nickname]', $vcard_safe['firstname'] .
         '-' . $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
- * 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'])) {
     echo addHidden('addaddr[email]', $vcard_nice['email;internet']);
 } else {
+    $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
+    $header = $message->rfc822_header;
+    $from_name = $header->getAddr_s('from');
+
     echo '</td></tr>' .
          '<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>' .
@@ -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">
 <tr><td bgcolor="<?php echo $color[4]; ?>">
 </td></tr></table>
-</body></html>
+</body></html>
\ No newline at end of file