From 916669ad08a0259c8a4aac6e592335c734aa5b82 Mon Sep 17 00:00:00 2001 From: jervfors Date: Tue, 26 Oct 2004 05:29:10 +0000 Subject: [PATCH] Suggesting senders address if none is present in the vCard git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@8250 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- ChangeLog | 4 ++-- functions/attachment_common.php | 2 +- functions/url_parser.php | 27 ++++++++++++++++++++++++++- po/squirrelmail.pot | 4 ++-- src/vcard.php | 18 +++++++++++------- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 20d770d4..37332a36 100644 --- 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 diff --git a/functions/attachment_common.php b/functions/attachment_common.php index 3e65014f..d0c7288e 100644 --- a/functions/attachment_common.php +++ b/functions/attachment_common.php @@ -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']; } diff --git a/functions/url_parser.php b/functions/url_parser.php index ca1b52d1..8525cc24 100644 --- a/functions/url_parser.php +++ b/functions/url_parser.php @@ -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('&' => '&')); + $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 diff --git a/po/squirrelmail.pot b/po/squirrelmail.pot index 1e3cb0d2..a36101dd 100644 --- a/po/squirrelmail.pot +++ b/po/squirrelmail.pot @@ -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 \n" "Language-Team: LANGUAGE \n" @@ -1059,7 +1059,7 @@ msgstr "" msgid "View" msgstr "" -msgid "Business Card" +msgid "View business Card" msgstr "" msgid "Sunday" diff --git a/src/vcard.php b/src/vcard.php index b3d42b10..b4f77e5a 100644 --- a/src/vcard.php +++ b/src/vcard.php @@ -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 '' . '' . _("E-mail address") . ':' . - addInput('addaddr[email]', '', '20'); + addInput('addaddr[email]', + getEmail(decodeHeader($from_name)), '20'); } echo '' . @@ -239,4 +243,4 @@ echo ' - + \ No newline at end of file -- 2.25.1