* @return string The text, encoded only if it contains non-ASCII
* characters.
*/
- static public function encode($text, $charset = null)
+ static public function encode($text, $charset)
{
- if (is_null($charset)) {
- $charset = $GLOBALS['registry']->getCharset();
- }
$charset = Horde_String::lower($charset);
if (($charset == 'us-ascii') || !self::is8bit($text, $charset)) {
* characters.
* @throws Horde_Mime_Exception
*/
- static public function encodeAddress($addresses, $charset = null,
+ static public function encodeAddress($addresses, $charset,
$defserver = null)
{
if (!is_array($addresses)) {
*
* @return string The decoded text.
*/
- static public function decode($string, $to_charset = null)
+ static public function decode($string, $to_charset)
{
if (($pos = strpos($string, '=?')) === false) {
return $string;
$encoded_text = substr($search, 0, $end);
$rest = substr($string, (strlen($preceding . $charset . $encoding . $encoded_text) + 6));
- if (is_null($to_charset)) {
- $to_charset = $GLOBALS['registry']->getCharset();
- }
-
switch ($encoding) {
case 'Q':
case 'q':
/**
* Constructor.
*
- * @param Horde_Mime_Headers $mime_headers A Horde_Mime_Headers object.
+ * @param Horde_Mime_Headers $mime_headers A headers object.
*/
- public function __construct($headers = null)
+ public function __construct(Horde_Mime_Headers $headers)
{
$this->_headers = $headers;
}
*/
public function getMdnReturnAddr()
{
- /* RFC 3798 [2.1] requires the Disposition-Notificaion-To header
+ /* RFC 3798 [2.1] requires the Disposition-Notification-To header
* for an MDN to be created. */
return $this->_headers->getValue('Disposition-Notification-To');
}
* </pre>
* @param string $name The name of the local server.
* @param Mail $mailer A Mail driver.
+ * @param array $opts Additional options:
+ * <pre>
+ * 'charset' - (string) Default charset.
+ * DEFAULT: NONE
+ * 'from_addr' - (string) From address.
+ * DEFAULT: NONE
+ * </pre>
* @param array $mod The list of modifications.
* <pre>
* Per RFC 3798 [3.2.6.3] the following modifications are valid:
* @throws Horde_Mime_Exception
*/
public function generate($action, $sending, $type, $name, $mailer,
- $mod = array(), $err = array())
+ array $opts = array(), array $mod = array(),
+ array $err = array())
{
- /* Set up some variables we use later. */
- $identity = $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getIdentity();
- $from_addr = $identity->getDefaultFromAddress();
+ $opts = array_merge(array(
+ 'charset' => null,
+ 'from_addr' => null
+ ), $opts);
$to = $this->getMdnReturnAddr();
$ua = $this->_headers->getUserAgent();
$msg_headers->addMessageIdHeader();
$msg_headers->addUserAgentHeader($ua);
$msg_headers->addHeader('Date', date('r'));
- $msg_headers->addHeader('From', $from_addr);
+ if ($opts['from_addr']) {
+ $msg_headers->addHeader('From', $opts['from_addr']);
+ }
$msg_headers->addHeader('To', $this->getMdnReturnAddr());
$msg_headers->addHeader('Subject', _("Disposition Notification"));
$msg->setType('multipart/report');
$msg->setContentTypeParameter('report-type', 'disposition-notification');
- $charset = $GLOBALS['registry']->getCharset();
-
/* The first part is a human readable message. */
$part_one = new Horde_Mime_Part('text/plain');
- $part_one->setCharset($charset);
+ $part_one->setCharset($opts['charset']);
if ($type == 'displayed') {
$contents = sprintf(_("The message sent on %s to %s with subject \"%s\" has been displayed.\n\nThis is no guarantee that the message has been read or understood."), $this->_headers->getValue('Date'), $this->_headers->getValue('To'), $this->_headers->getValue('Subject'));
- $flowed = new Horde_Text_Flowed($contents, $charset);
+ $flowed = new Horde_Text_Flowed($contents, $opts['charset']);
$flowed->setDelSp(true);
$part_one->setContentTypeParameter('format', 'flowed');
$part_one->setContentTypeParameter('DelSp', 'Yes');
if (!empty($orig_recip)) {
$part_two_text[] = 'Original-Recipient: rfc822;' . $orig_recip . "\n";
}
- $part_two_text[] = 'Final-Recipient: rfc822;' . $from_addr . "\n";
+ if ($opts['from_addr']) {
+ $part_two_text[] = 'Final-Recipient: rfc822;' . $from_addr . "\n";
+ }
if (!empty($msg_id)) {
$part_two_text[] = 'Original-Message-ID: rfc822;' . $msg_id . "\n";
}
* Add a MDN (read receipt) request headers to the Horde_Mime_Headers::
* object.
*
- * @param Horde_Mime_Headers $ob The object to add the headers to.
- * @param string $to The address the receipt should be
- * mailed to.
+ * @param string $to The address the receipt should be mailed to.
*/
- public function addMdnRequestHeaders($ob, $to)
+ public function addMdnRequestHeaders($to)
{
/* This is the RFC 3798 way of requesting a receipt. */
- $ob->addHeader('Disposition-Notification-To', $to);
+ $this->_headers->addHeader('Disposition-Notification-To', $to);
}
}
/* Check to see if an MDN has been requested. */
$mdn = new Horde_Mime_Mdn($headers);
- $return_addr = $mdn->getMDNReturnAddr();
+ $return_addr = $mdn->getMdnReturnAddr();
if (!$return_addr) {
return false;
}
/* Send out the MDN now. */
try {
- $mdn->generate(false, $confirmed, 'displayed', $GLOBALS['conf']['server']['name'], $GLOBALS['injector']->getInstance('IMP_Mail'));
+ $mdn->generate(
+ false,
+ $confirmed,
+ 'displayed',
+ $GLOBALS['conf']['server']['name'],
+ $GLOBALS['injector']->getInstance('IMP_Mail'),
+ array(
+ 'charset' => $GLOBALS['registry']->getCharset(),
+ 'from_addr' => $GLOBALS['injector']->getInstance('Horde_Prefs_Identity')->getIdentity()->getDefaultFromAddress()
+ )
+ );
IMP_Maillog::log('mdn', $msg_id, 'displayed');
$success = true;