Skip to content

Commit

Permalink
[mms] Auto-detect EAI support on mail backends and provide validation…
Browse files Browse the repository at this point in the history
… feedback without the need to submit to the backend.
  • Loading branch information
slusarz committed Oct 26, 2014
1 parent aa27edb commit ec218ea
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 28 deletions.
2 changes: 2 additions & 0 deletions imp/docs/CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
v7.0.0-git
----------

[mms] Auto-detect EAI support on mail backends and provide validation feedback
without the need to submit to the backend.
[mms] Removed basic view.
[mms] Do autocomplete search on browser, if sufficient data exists, to save
calls to contacts backend.
Expand Down
57 changes: 45 additions & 12 deletions imp/lib/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ public function saveDraft($headers, $message, array $opts = array())
*/
protected function _saveDraftMsg($headers, $message, $opts)
{
$has_session = (bool)$GLOBALS['registry']->getAuth();
global $injector, $registry;

$has_session = (bool)$registry->getAuth();

/* Set up the base message now. */
$base = $this->_createMimeMessage(new Horde_Mail_Rfc822_List(), $message, array(
Expand All @@ -241,12 +243,19 @@ protected function _saveDraftMsg($headers, $message, $opts)
));
$base->isBasePart(true);

$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();

$recip_list = $this->recipientList($headers);
if (!empty($opts['verify_email'])) {
foreach ($recip_list['list'] as $val) {
try {
/* For draft messages, the key is whether the IMAP server
* supports EAI addresses. */
$utf8 = $imp_imap->client_ob->capability->query(
'UTF8', 'ACCEPT'
);
IMP::parseAddressList($val->writeAddress(true), array(
'validate' => true
'validate' => $utf8 ? 'eai' : true
));
} catch (Horde_Mail_Exception $e) {
throw new IMP_Compose_Exception(sprintf(
Expand All @@ -264,7 +273,6 @@ protected function _saveDraftMsg($headers, $message, $opts)

/* Add information necessary to log replies/forwards when finally
* sent. */
$imp_imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create();
if ($this->_replytype) {
try {
$indices = $this->getMetadata('indices');
Expand Down Expand Up @@ -983,12 +991,18 @@ public function buildAndSendMessage(
/**
* Save message to sent-mail mailbox, if configured to do so.
*
* @param array $header See buildAndSendMessage().
* @param Horde_Mime_Headers $headers Headers object.
* @param Horde_Mime_Part $save_msg Message data to save.
* @param array $opts See buildAndSendMessage()
*/
protected function _saveToSentMail($header, $headers, $save_msg, $opts)
* @param array $header See buildAndSendMessage().
* @param Horde_Mime_Headers $headers Headers object.
* @param Horde_Mime_Part $save_msg Message data to save.
* @param Horde_Mail_Rfc822_List $recips Recipient list.
* @param array $opts See buildAndSendMessage()
*/
protected function _saveToSentMail($header,
Horde_Mime_Headers $headers,
Horde_Mime_Part $save_msg,
Horde_Mail_Rfc822_List $recips,
$opts
)
{
global $injector, $language, $notification, $prefs;

Expand All @@ -1000,6 +1014,24 @@ protected function _saveToSentMail($header, $headers, $save_msg, $opts)
return;
}

$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();

/* If message contains EAI addresses, we need to verify that the IMAP
* server can handle this data in order to save. */
foreach ($recips as $val) {
if ($val->eai) {
if ($imp_imap->client_ob->capability->query('UTF8', 'ACCEPT')) {
break;
}

$notification->push(sprintf(
_("Message sent successfully, but not saved to %s."),
$sent_mail->display
));
return;
}
}

/* Keep Bcc: headers on saved messages. */
if (count($header['bcc'])) {
$headers->addHeader('Bcc', $header['bcc']);
Expand Down Expand Up @@ -1028,7 +1060,6 @@ protected function _saveToSentMail($header, $headers, $save_msg, $opts)
}

/* Generate the message string. */
$imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
$fcc = $save_msg->toString(array(
'defserver' => $imp_imap->config->maildomain,
'headers' => $headers,
Expand Down Expand Up @@ -1288,9 +1319,11 @@ protected function _prepSendMessageEncode(Horde_Mail_Rfc822_List $email,

try {
/* We have written address, but it still may not be valid.
* So double-check. */
* So double-check. Key here is MTA server support for
* UTF-8. */
$utf8 = $injector->getInstance('IMP_Mail')->eai;
$alist = IMP::parseAddressList($tmp, array(
'validate' => true
'validate' => $utf8 ? 'eai' : true
));

$error = null;
Expand Down
15 changes: 2 additions & 13 deletions imp/lib/Prefs/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,20 +533,9 @@ public function setValue($key, $val, $identity = null)
}

/* Validate Reply-To, Alias, Tie-to, and BCC addresses. */
$ob = IMP::parseAddressList($val, array(
$val = IMP::parseAddressList($val, array(
'limit' => ($val == 'replyto_addr') ? 1 : 0
));

foreach ($ob as $address) {
try {
IMP::parseAddressList($address, array(
'validate' => true
));
} catch (Horde_Mail_Exception $e) {
throw new Horde_Prefs_Exception(sprintf(_("\"%s\" is not a valid email address.", strval($address))));
}
}
$val = $ob->addresses;
))->addresses;
break;

case IMP_Mailbox::MBOX_SENT:
Expand Down
4 changes: 1 addition & 3 deletions imp/lib/Prefs/Special/PgpPrivateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ public function update(Horde_Core_Prefs_Ui $ui)
!empty($conf['pgp']['keylength'])) {
/* Sanity checking for email address. */
try {
$email = IMP::parseAddressList($ui->vars->generate_email, array(
'validate' => true
));
$email = IMP::parseAddressList($ui->vars->generate_email);
} catch (Horde_Mail_Exception $e) {
$notification->push($e);
return false;
Expand Down
1 change: 1 addition & 0 deletions imp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [mms] Auto-detect EAI support on mail backends and provide validation feedback without the need to submit to the backend.
* [mms] Removed basic view.
* [mms] Do autocomplete search on browser, if sufficient data exists, to save calls to contacts backend.
* [mms] Removed minimal view.
Expand Down

0 comments on commit ec218ea

Please sign in to comment.