Skip to content

Commit

Permalink
Better handling of Bcc header
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Mar 19, 2015
1 parent ef06742 commit a52e350
Showing 1 changed file with 11 additions and 31 deletions.
42 changes: 11 additions & 31 deletions imp/lib/Compose.php
Expand Up @@ -275,10 +275,7 @@ protected function _saveDraftMsg($headers, $message, $opts)
$headers = array_merge($headers, $recip_list['header']);

/* Initalize a header object for the draft. */
$draft_headers = $this->_prepareHeaders(
$headers,
array_merge($opts, array('bcc' => true))
);
$draft_headers = $this->_prepareHeaders($headers, $opts);

/* Add information necessary to log replies/forwards when finally
* sent. */
Expand Down Expand Up @@ -799,9 +796,6 @@ public function buildAndSendMessage(

/* Initalize a header object for the outgoing message. */
$headers = $this->_prepareHeaders($header, $opts);
$bcc = isset($header['bcc'])
? $header['bcc']
: null;

/* Add a Received header for the hop from browser to server. */
$headers->addHeaderOb(
Expand Down Expand Up @@ -846,12 +840,6 @@ public function buildAndSendMessage(
}
}
$recip = $this->recipientList($tmp_recip);
if (isset($tmp_recip['bcc'])) {
$bcc = $tmp_recip['bcc'];
unset($headers['bcc']);
} else {
$bcc = null;
}
} catch (Horde_Exception_HookNotSet $e) {}

/* Get from address. Done after pre_sent hook since from address could
Expand Down Expand Up @@ -970,13 +958,7 @@ public function buildAndSendMessage(
);

/* Save message to the sent mail mailbox. */
$this->_saveToSentMail(
$bcc,
$headers,
$message,
$recip['list'],
$opts
);
$this->_saveToSentMail($headers, $message, $recip['list'], $opts);

/* Delete the attachment data. */
$this->deleteAllAttachments();
Expand Down Expand Up @@ -1191,14 +1173,12 @@ protected function _logSentmail(
/**
* Save message to sent-mail mailbox, if configured to do so.
*
* @param string $bcc List of BCC addresses.
* @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(
$bcc,
Horde_Mime_Headers $headers,
Horde_Mime_Part $save_msg,
Horde_Mail_Rfc822_List $recips,
Expand Down Expand Up @@ -1233,11 +1213,6 @@ protected function _saveToSentMail(
}
}

/* Keep Bcc: headers on saved messages. */
if (count($bcc)) {
$headers->addHeader('Bcc', $bcc);
}

/* Strip attachments if requested. */
if (!empty($opts['strip_attachments'])) {
$save_msg->buildMimeIds();
Expand Down Expand Up @@ -1291,7 +1266,6 @@ protected function _saveToSentMail(
* @param array $headers Array with 'from', 'to', 'cc', 'bcc', and
* 'subject' values.
* @param array $opts An array of options w/the following keys:
* - bcc: (boolean) Add BCC header to output.
* - priority: (string) The message priority ('high', 'normal', 'low').
*
* @return Horde_Mime_Headers Headers object with the appropriate headers
Expand All @@ -1304,13 +1278,13 @@ protected function _prepareHeaders($headers, array $opts = array())
$ob->addHeaderOb(Horde_Mime_Headers_Date::create());
$ob->addHeaderOb(Horde_Mime_Headers_MessageId::create());

$hdrs = array_filter(array(
$hdrs = array(
'From' => 'from',
'To' => 'to',
'Cc' => 'cc',
'Bcc' => empty($opts['bcc']) ? null : 'bcc',
'Bcc' => 'bcc',
'Subject' => 'subject'
));
);

foreach ($hdrs as $key => $val) {
if (isset($headers[$val]) &&
Expand Down Expand Up @@ -1380,6 +1354,12 @@ public function sendMessage(Horde_Mail_Rfc822_List $email,
$opts['encode'] = Horde_Mime_Part::ENCODE_7BIT;
}

/* Remove Bcc header if it exists. */
if (isset($headers['bcc'])) {
$headers = clone $headers;
unset($headers['bcc']);
}

try {
$message->send($email, $headers, $GLOBALS['injector']->getInstance('IMP_Mail'), $opts);
} catch (Horde_Mime_Exception $e) {
Expand Down

0 comments on commit a52e350

Please sign in to comment.