/** * @dataProvider commentOutputProvider */ public function testCommentOutput($expected, $params) { $ob = new Horde_Mail_Rfc822_Address(); foreach ($params as $key => $val) { $ob->{$key} = $val; } $this->assertEquals($expected, $ob->writeAddress(array('comment' => true))); }
/** * Constructor. * * @param string|Horde_Mail_Rfc822_Object $from The email address of the * original sender. * @param Horde_Mime_Headers $h The headers object for * the message. * @param string $attrib Use this for the * attribution config * instead of the default * prefs version. */ public function __construct($from, Horde_Mime_Headers $h, $attrib = null) { global $prefs; $this->_text = preg_replace_callback('/\\%./', function ($matches) use($from, $h) { switch ($matches[0]) { case '%n': /* New line. */ return "\n"; case '%%': /* Percent character. */ return '%'; case '%f': /* Name and email address of original sender. */ if ($from) { $from = new Horde_Mail_Rfc822_Address($from); return $from->writeAddress(array('noquote' => true)); } return _("Unknown Sender"); case '%a': /* Senders email address(es). */ /* Senders email address(es). */ case '%p': /* Senders name(s). */ $out = array(); foreach (IMP::parseAddressList($from) as $addr) { if ($matches[0] == '%a') { if (!is_null($addr->mailbox)) { $out[] = $addr->bare_address; } } else { $out[] = $addr->label; } } return count($out) ? implode(', ', $out) : _("Unknown Sender"); case '%r': /* RFC 822 date and time. */ return $h['Date']; case '%d': /* Date as ddd, dd mmm yyyy. */ return strftime("%a, %d %b %Y", strtotime($h['Date'])); case '%c': /* Date and time in locale's default. */ /* Date and time in locale's default. */ case '%x': /* Date in locale's default. */ return strftime($matches[0], strtotime($h['Date'])); case '%m': /* Message-ID. */ return strval($h['Message-Id']); case '%s': /* Message subject. */ return strlen($subject = $h['Subject']) ? $subject : _("[No Subject]"); default: return ''; } }, is_null($attrib) ? $prefs->getValue('attrib_text') : $attrib); }
/** * Return the message's From: address. * * @return string The From address of this message. * @throws Horde_ActiveSync_Exception @since 2.27.0 */ public function getFromAddress() { $from = $this->envelope->from->addresses; try { $a = new Horde_Mail_Rfc822_Address(current($from)); } catch (Horde_ActiveSync_Exception $e) { throw new Horde_ActiveSync_Exception($e); } return $a->writeAddress(false); }
try { $registry->call('tickets/addAttachment', array('ticket_id' => $ticketId, 'name' => $attachment['name'], 'data' => file_get_contents($attachment['tmp_name']))); } catch (Horde_Exception $e) { $notification->push($e); } } $redirect_url->redirect(); } /* Add user's name to the email address if provided. */ if ($name) { $addr_ob = new Horde_Mail_Rfc822_Address($email); if (is_null($addr_ob->host)) { $addr_ob->host = $conf['problems']['maildomain']; } $addr_ob->personal = $name; $email = $addr_ob->writeAddress(true); } $mail = new Horde_Mime_Mail(array('body' => $body, 'Subject' => _("[Problem Report]") . ' ' . $subject, 'To' => $conf['problems']['email'], 'From' => $email)); $mail->addHeader('Sender', 'horde-problem@' . $conf['problems']['maildomain']); /* Add attachment. */ if ($attachment) { $mail->addAttachment($attachment['tmp_name'], $attachment['name'], $attachment['type']); } try { $mail->send($injector->getInstance('Horde_Mail')); /* Success. */ Horde::log(sprintf("%s Message sent to %s from %s", $_SERVER['REMOTE_ADDR'], preg_replace('/^.*<([^>]+)>.*$/', '$1', $conf['problems']['email']), preg_replace('/^.*<([^>]+)>.*$/', '$1', $email)), 'INFO'); /* Return to previous page and exit this script. */ $redirect_url->redirect(); } catch (Horde_Exception $e) { $notification->push($e);
public function testParsingPersonalPartWithQuotes() { $email = '"Test \\"F-oo\\" Bar" <*****@*****.**>'; $ob = new Horde_Mail_Rfc822_Address($email); $this->assertEquals('"Test \\"F-oo\\" Bar" <*****@*****.**>', $ob->writeAddress()); $this->assertEquals($email, $ob->writeAddress(true)); }
/** * Return the message's From: address. * * @return string The From address of this message. */ public function getFromAddress() { $from = $this->_envelope->from->addresses; $a = new Horde_Mail_Rfc822_Address(current($from)); return $a->writeAddress(false); }
/** */ public function generateKey($opts) { $skey = $this->_generateSecretKeyPacket($opts['keylength'], 'OpenPGP_SecretKeyPacket'); $id = new Horde_Mail_Rfc822_Address($opts['email']); if (strlen($opts['comment'])) { $id->comment[] = $opts['comment']; } if (strlen($opts['name'])) { $id->personal = $opts['name']; } /* This is the private key we are creating. */ $key = new OpenPGP_Message(array($skey, new OpenPGP_UserIDPacket($id->writeAddress(array('comment' => true))))); $rsa = OpenPGP_Crypt_RSA::convert_private_key($skey); $rsa->setHash(Horde_String::lower($opts['hash'])); $rsa_sign_func = array('RSA' => array($opts['hash'] => function ($data) use($rsa) { return array($rsa->sign($data)); })); /* Create signature packet. */ $sig = new OpenPGP_SignaturePacket($key, 'RSA', $opts['hash']); /* "Generic certification of a User ID and Public-Key packet." */ $sig->signature_type = 0x10; /* Add subpacket information. */ $sig->hashed_subpackets[] = new OpenPGP_SignaturePacket_KeyFlagsPacket(array(0x3)); $sig->hashed_subpackets[] = new OpenPGP_SignaturePacket_PreferredSymmetricAlgorithmsPacket(array(0x9, 0x8, 0x7, 0x2)); $sig->hashed_subpackets[] = new OpenPGP_SignaturePacket_PreferredHashAlgorithmsPacket(array(0x8, 0x9, 0xa, 0xb, 0x2)); $sig->hashed_subpackets[] = new OpenPGP_SignaturePacket_PreferredCompressionAlgorithmsPacket(array(0x2, 0x1)); $ks_prefs = new OpenPGP_SignaturePacket_KeyServerPreferencesPacket(); $ks_prefs->no_modify = true; $sig->hashed_subpackets[] = $ks_prefs; $sig->hashed_subpackets[] = new OpenPGP_SignaturePacket_FeaturesPacket(array(0x1)); if (isset($opts['expire'])) { $sig->hashed_subpackets[] = new OpenPGP_SignaturePacket_KeyExpirationTimePacket($opts['expire'] - time()); } $sig->unhashed_subpackets[] = new OpenPGP_SignaturePacket_IssuerPacket(substr($skey->fingerprint, -16)); $key[] = $sig; /* Create self-signature. */ $sig->sign_data($rsa_sign_func); /* OpenPGP currently (as of April 2015) encrypts passphrases w/ * AES-128 & SHA-1, so use this strategy. */ if (strlen($opts['passphrase'])) { $cipher = new Crypt_AES(CRYPT_AES_MODE_CFB); $cipher->setKeyLength(128); $s2k = new OpenPGP_S2K(crypt_random_string(8), 2); $cipher->setKey($s2k->make_key($opts['passphrase'], 16)); $iv = crypt_random_string(16); $this->_encryptPrivateKey($skey, $cipher, $s2k, $iv); } /* Encryption subkey. See RFC 4880 [5.5.1.2] (by convention, top-level * key is used for signing and subkeys are used for encryption) */ $ekey = $this->_generateSecretKeyPacket($opts['keylength'], 'OpenPGP_SecretSubkeyPacket'); /* Computing signature: RFC 4880 [5.2.4] */ $sig = new OpenPGP_SignaturePacket(implode('', $skey->fingerprint_material()) . implode('', $ekey->fingerprint_material()), 'RSA', $opts['hash']); /* This is a "Subkey Binding Signature". */ $sig->signature_type = 0x18; $sig->hashed_subpackets[] = new OpenPGP_SignaturePacket_KeyFlagsPacket(array(0xc)); $sig->unhashed_subpackets[] = new OpenPGP_SignaturePacket_IssuerPacket(substr($skey->fingerprint, -16)); $sig->sign_data($rsa_sign_func); if (strlen($opts['passphrase'])) { $this->_encryptPrivateKey($ekey, $cipher, $s2k, $iv); } $key[] = $ekey; $key[] = $sig; return new Horde_Pgp_Element_PrivateKey($key); }