Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/storage/PhabricatorMetaMTAMail.php
Show First 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | public function setVarySubjectPrefix($prefix) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setBody($body) { | public function setBody($body) { | ||||
$this->setParam('body', $body); | $this->setParam('body', $body); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getBody() { | public function setHTMLBody($html) { | ||||
return $this->getParam('body'); | $this->setParam('html-body', $html); | ||||
return $this; | |||||
} | } | ||||
public function setIsHTML($html) { | public function getBody() { | ||||
$this->setParam('is-html', $html); | return $this->getParam('body'); | ||||
return $this; | |||||
} | } | ||||
public function setIsErrorEmail($is_error) { | public function setIsErrorEmail($is_error) { | ||||
$this->setParam('is-error', $is_error); | $this->setParam('is-error', $is_error); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getIsErrorEmail() { | public function getIsErrorEmail() { | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | try { | ||||
$is_threaded = (bool)idx($params, 'thread-id'); | $is_threaded = (bool)idx($params, 'thread-id'); | ||||
$reply_to_name = idx($params, 'reply-to-name', ''); | $reply_to_name = idx($params, 'reply-to-name', ''); | ||||
unset($params['reply-to-name']); | unset($params['reply-to-name']); | ||||
$add_cc = array(); | $add_cc = array(); | ||||
$add_to = array(); | $add_to = array(); | ||||
// Only try to use preferences if everything is multiplexed, so we | |||||
// get consistent behavior. | |||||
$use_prefs = self::shouldMultiplexAllMail(); | |||||
$prefs = null; | |||||
if ($use_prefs) { | |||||
// If multiplexing is enabled, some recipients will be in "Cc" | |||||
// rather than "To". We'll move them to "To" later (or supply a | |||||
// dummy "To") but need to look for the recipient in either the | |||||
// "To" or "Cc" fields here. | |||||
$target_phid = head(idx($params, 'to', array())); | |||||
if (!$target_phid) { | |||||
$target_phid = head(idx($params, 'cc', array())); | |||||
} | |||||
if ($target_phid) { | |||||
$user = id(new PhabricatorUser())->loadOneWhere( | |||||
'phid = %s', | |||||
$target_phid); | |||||
if ($user) { | |||||
$prefs = $user->loadPreferences(); | |||||
} | |||||
} | |||||
} | |||||
foreach ($params as $key => $value) { | foreach ($params as $key => $value) { | ||||
switch ($key) { | switch ($key) { | ||||
case 'from': | case 'from': | ||||
$from = $value; | $from = $value; | ||||
$actor_email = null; | $actor_email = null; | ||||
$actor_name = null; | $actor_name = null; | ||||
$actor = idx($actors, $from); | $actor = idx($actors, $from); | ||||
if ($actor) { | if ($actor) { | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | try { | ||||
$value = $this->getAttachments(); | $value = $this->getAttachments(); | ||||
foreach ($value as $attachment) { | foreach ($value as $attachment) { | ||||
$mailer->addAttachment( | $mailer->addAttachment( | ||||
$attachment->getData(), | $attachment->getData(), | ||||
$attachment->getFilename(), | $attachment->getFilename(), | ||||
$attachment->getMimeType()); | $attachment->getMimeType()); | ||||
} | } | ||||
break; | break; | ||||
case 'body': | |||||
$max = PhabricatorEnv::getEnvConfig('metamta.email-body-limit'); | |||||
if (strlen($value) > $max) { | |||||
$value = phutil_utf8_shorten($value, $max); | |||||
$value .= "\n"; | |||||
$value .= pht('(This email was truncated at %d bytes.)', $max); | |||||
} | |||||
$mailer->setBody($value); | |||||
break; | |||||
case 'subject': | case 'subject': | ||||
// Only try to use preferences if everything is multiplexed, so we | |||||
// get consistent behavior. | |||||
$use_prefs = self::shouldMultiplexAllMail(); | |||||
$prefs = null; | |||||
if ($use_prefs) { | |||||
// If multiplexing is enabled, some recipients will be in "Cc" | |||||
// rather than "To". We'll move them to "To" later (or supply a | |||||
// dummy "To") but need to look for the recipient in either the | |||||
// "To" or "Cc" fields here. | |||||
$target_phid = head(idx($params, 'to', array())); | |||||
if (!$target_phid) { | |||||
$target_phid = head(idx($params, 'cc', array())); | |||||
} | |||||
if ($target_phid) { | |||||
$user = id(new PhabricatorUser())->loadOneWhere( | |||||
'phid = %s', | |||||
$target_phid); | |||||
if ($user) { | |||||
$prefs = $user->loadPreferences(); | |||||
} | |||||
} | |||||
} | |||||
$subject = array(); | $subject = array(); | ||||
if ($is_threaded) { | if ($is_threaded) { | ||||
$add_re = PhabricatorEnv::getEnvConfig('metamta.re-prefix'); | $add_re = PhabricatorEnv::getEnvConfig('metamta.re-prefix'); | ||||
if ($prefs) { | if ($prefs) { | ||||
$add_re = $prefs->getPreference( | $add_re = $prefs->getPreference( | ||||
PhabricatorUserPreferences::PREFERENCE_RE_PREFIX, | PhabricatorUserPreferences::PREFERENCE_RE_PREFIX, | ||||
Show All 22 Lines | try { | ||||
$subject[] = $vary_prefix; | $subject[] = $vary_prefix; | ||||
} | } | ||||
} | } | ||||
$subject[] = $value; | $subject[] = $value; | ||||
$mailer->setSubject(implode(' ', array_filter($subject))); | $mailer->setSubject(implode(' ', array_filter($subject))); | ||||
break; | break; | ||||
case 'is-html': | |||||
if ($value) { | |||||
$mailer->setIsHTML(true); | |||||
} | |||||
break; | |||||
case 'is-bulk': | case 'is-bulk': | ||||
if ($value) { | if ($value) { | ||||
if (PhabricatorEnv::getEnvConfig('metamta.precedence-bulk')) { | if (PhabricatorEnv::getEnvConfig('metamta.precedence-bulk')) { | ||||
$mailer->addHeader('Precedence', 'bulk'); | $mailer->addHeader('Precedence', 'bulk'); | ||||
} | } | ||||
} | } | ||||
break; | break; | ||||
case 'thread-id': | case 'thread-id': | ||||
Show All 31 Lines | try { | ||||
case 'vary-subject-prefix': | case 'vary-subject-prefix': | ||||
// Handled above. | // Handled above. | ||||
break; | break; | ||||
default: | default: | ||||
// Just discard. | // Just discard. | ||||
} | } | ||||
} | } | ||||
$body = idx($params, 'body', ''); | |||||
$max = PhabricatorEnv::getEnvConfig('metamta.email-body-limit'); | |||||
if (strlen($body) > $max) { | |||||
$body = phutil_utf8_shorten($body, $max); | |||||
epriestley: Oh -- although it's outside of the scope of this diff, this isn't quite correct. I can send you… | |||||
$body .= "\n"; | |||||
$body .= pht('(This email was truncated at %d bytes.)', $max); | |||||
} | |||||
$mailer->setBody($body); | |||||
$html_emails = false; | |||||
if ($use_prefs && $prefs) { | |||||
$html_emails = $prefs->getPreference( | |||||
PhabricatorUserPreferences::PREFERENCE_HTML_EMAILS, | |||||
$html_emails); | |||||
} | |||||
if ($html_emails && isset($params['html-body'])) { | |||||
$mailer->setHTMLBody($params['html-body']); | |||||
} | |||||
if (!$add_to && !$add_cc) { | if (!$add_to && !$add_cc) { | ||||
$this->setStatus(self::STATUS_VOID); | $this->setStatus(self::STATUS_VOID); | ||||
$this->setMessage( | $this->setMessage( | ||||
'Message has no valid recipients: all To/Cc are disabled, invalid, '. | 'Message has no valid recipients: all To/Cc are disabled, invalid, '. | ||||
'or configured not to receive this mail.'); | 'or configured not to receive this mail.'); | ||||
return $this->save(); | return $this->save(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 347 Lines • Show Last 20 Lines |
Oh -- although it's outside of the scope of this diff, this isn't quite correct. I can send you a followup to fix it.