Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/engine/PhabricatorMailEmailEngine.php
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | if ($must_encrypt) { | ||||
$parts[] = PhabricatorEnv::getProductionURI($mail->getURI()); | $parts[] = PhabricatorEnv::getProductionURI($mail->getURI()); | ||||
$body = implode("\n\n", $parts); | $body = implode("\n\n", $parts); | ||||
} else { | } else { | ||||
$body = $raw_body; | $body = $raw_body; | ||||
} | } | ||||
$body_limit = PhabricatorEnv::getEnvConfig('metamta.email-body-limit'); | $body_limit = PhabricatorEnv::getEnvConfig('metamta.email-body-limit'); | ||||
$body = phutil_string_cast($body); | |||||
if (strlen($body) > $body_limit) { | if (strlen($body) > $body_limit) { | ||||
$body = id(new PhutilUTF8StringTruncator()) | $body = id(new PhutilUTF8StringTruncator()) | ||||
->setMaximumBytes($body_limit) | ->setMaximumBytes($body_limit) | ||||
->truncateString($body); | ->truncateString($body); | ||||
$body .= "\n"; | $body .= "\n"; | ||||
$body .= pht('(This email was truncated at %d bytes.)', $body_limit); | $body .= pht('(This email was truncated at %d bytes.)', $body_limit); | ||||
} | } | ||||
$message->setTextBody($body); | $message->setTextBody($body); | ||||
$body_limit -= strlen($body); | $body_limit -= strlen($body); | ||||
// If we sent a different message body than we were asked to, record | // If we sent a different message body than we were asked to, record | ||||
// what we actually sent to make debugging and diagnostics easier. | // what we actually sent to make debugging and diagnostics easier. | ||||
if ($body !== $raw_body) { | if ($body !== $raw_body) { | ||||
$mail->setDeliveredBody($body); | $mail->setDeliveredBody($body); | ||||
} | } | ||||
if ($must_encrypt) { | if ($must_encrypt) { | ||||
$send_html = false; | $send_html = false; | ||||
} else { | } else { | ||||
$send_html = $this->shouldSendHTML(); | $send_html = $this->shouldSendHTML(); | ||||
} | } | ||||
if ($send_html) { | if ($send_html) { | ||||
$html_body = $mail->getHTMLBody(); | $html_body = $mail->getHTMLBody(); | ||||
if (strlen($html_body)) { | if (phutil_nonempty_string($html_body)) { | ||||
// NOTE: We just drop the entire HTML body if it won't fit. Safely | // NOTE: We just drop the entire HTML body if it won't fit. Safely | ||||
// truncating HTML is hard, and we already have the text body to fall | // truncating HTML is hard, and we already have the text body to fall | ||||
// back to. | // back to. | ||||
if (strlen($html_body) <= $body_limit) { | if (strlen($html_body) <= $body_limit) { | ||||
$message->setHTMLBody($html_body); | $message->setHTMLBody($html_body); | ||||
$body_limit -= strlen($html_body); | $body_limit -= strlen($html_body); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Pass the headers to the mailer, then save the state so we can show | // Pass the headers to the mailer, then save the state so we can show | ||||
// them in the web UI. If the mail must be encrypted, we remove headers | // them in the web UI. If the mail must be encrypted, we remove headers | ||||
// which are not on a strict whitelist to avoid disclosing information. | // which are not on a strict whitelist to avoid disclosing information. | ||||
$filtered_headers = $this->filterHeaders($headers, $must_encrypt); | $filtered_headers = $this->filterHeaders($headers, $must_encrypt); | ||||
$message->setHeaders($filtered_headers); | $message->setHeaders($filtered_headers); | ||||
$mail->setUnfilteredHeaders($headers); | $mail->setUnfilteredHeaders($headers); | ||||
$mail->setDeliveredHeaders($headers); | $mail->setDeliveredHeaders($headers); | ||||
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { | if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { | ||||
$mail->setMessage( | $mail->setMessage( | ||||
pht( | pht( | ||||
'Phabricator is running in silent mode. See `%s` '. | 'This software is running in silent mode. See `%s` '. | ||||
'in the configuration to change this setting.', | 'in the configuration to change this setting.', | ||||
'phabricator.silent')); | 'phabricator.silent')); | ||||
return null; | return null; | ||||
} | } | ||||
return $message; | return $message; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | private function newFromEmailAddress() { | ||||
return $from_address; | return $from_address; | ||||
} | } | ||||
private function newReplyToEmailAddress() { | private function newReplyToEmailAddress() { | ||||
$mail = $this->getMail(); | $mail = $this->getMail(); | ||||
$reply_raw = $mail->getReplyTo(); | $reply_raw = $mail->getReplyTo(); | ||||
if (!strlen($reply_raw)) { | if (!phutil_nonempty_string($reply_raw)) { | ||||
return null; | return null; | ||||
} | } | ||||
$reply_address = new PhutilEmailAddress($reply_raw); | $reply_address = new PhutilEmailAddress($reply_raw); | ||||
// If we have a sending object, change the display name. | // If we have a sending object, change the display name. | ||||
$from_phid = $mail->getFrom(); | $from_phid = $mail->getFrom(); | ||||
$actor = $this->getActor($from_phid); | $actor = $this->getActor($from_phid); | ||||
if ($actor) { | if ($actor) { | ||||
$reply_address->setDisplayName($actor->getName()); | $reply_address->setDisplayName($actor->getName()); | ||||
} | } | ||||
// If we don't have a display name, fill in a default. | // If we don't have a display name, fill in a default. | ||||
if (!strlen($reply_address->getDisplayName())) { | if (!strlen($reply_address->getDisplayName())) { | ||||
$reply_address->setDisplayName(pht('Phabricator')); | $reply_address->setDisplayName(PlatformSymbols::getPlatformServerName()); | ||||
} | } | ||||
return $reply_address; | return $reply_address; | ||||
} | } | ||||
private function newToEmailAddresses() { | private function newToEmailAddresses() { | ||||
$mail = $this->getMail(); | $mail = $this->getMail(); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | private function newEmailSubject() { | ||||
$subject = array(); | $subject = array(); | ||||
if ($is_threaded) { | if ($is_threaded) { | ||||
if ($this->shouldAddRePrefix()) { | if ($this->shouldAddRePrefix()) { | ||||
$subject[] = 'Re:'; | $subject[] = 'Re:'; | ||||
} | } | ||||
} | } | ||||
$subject[] = trim($mail->getSubjectPrefix()); | $subject_prefix = $mail->getSubjectPrefix(); | ||||
$subject_prefix = phutil_string_cast($subject_prefix); | |||||
$subject_prefix = trim($subject_prefix); | |||||
$subject[] = $subject_prefix; | |||||
// If mail content must be encrypted, we replace the subject with | // If mail content must be encrypted, we replace the subject with | ||||
// a generic one. | // a generic one. | ||||
if ($must_encrypt) { | if ($must_encrypt) { | ||||
$encrypt_subject = $mail->getMustEncryptSubject(); | $encrypt_subject = $mail->getMustEncryptSubject(); | ||||
if (!strlen($encrypt_subject)) { | if (!strlen($encrypt_subject)) { | ||||
$encrypt_subject = pht('Object Updated'); | $encrypt_subject = pht('Object Updated'); | ||||
} | } | ||||
$subject[] = $encrypt_subject; | $subject[] = $encrypt_subject; | ||||
} else { | } else { | ||||
$vary_prefix = $mail->getVarySubjectPrefix(); | $vary_prefix = $mail->getVarySubjectPrefix(); | ||||
if (strlen($vary_prefix)) { | if (phutil_nonempty_string($vary_prefix)) { | ||||
if ($this->shouldVarySubject()) { | if ($this->shouldVarySubject()) { | ||||
$subject[] = $vary_prefix; | $subject[] = $vary_prefix; | ||||
} | } | ||||
} | } | ||||
$subject[] = $mail->getSubject(); | $subject[] = $mail->getSubject(); | ||||
} | } | ||||
foreach ($subject as $key => $part) { | foreach ($subject as $key => $part) { | ||||
if (!strlen($part)) { | if (!phutil_nonempty_string($part)) { | ||||
unset($subject[$key]); | unset($subject[$key]); | ||||
} | } | ||||
} | } | ||||
$subject = implode(' ', $subject); | $subject = implode(' ', $subject); | ||||
return $subject; | return $subject; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | /* -( Message Components )------------------------------------------------- */ | ||||
private function newEmailThreadingHeaders() { | private function newEmailThreadingHeaders() { | ||||
$mailer = $this->getMailer(); | $mailer = $this->getMailer(); | ||||
$mail = $this->getMail(); | $mail = $this->getMail(); | ||||
$headers = array(); | $headers = array(); | ||||
$thread_id = $mail->getThreadID(); | $thread_id = $mail->getThreadID(); | ||||
if (!strlen($thread_id)) { | if (!phutil_nonempty_string($thread_id)) { | ||||
return $headers; | return $headers; | ||||
} | } | ||||
$is_first = $mail->getIsFirstMessage(); | $is_first = $mail->getIsFirstMessage(); | ||||
// NOTE: Gmail freaks out about In-Reply-To and References which aren't in | // NOTE: Gmail freaks out about In-Reply-To and References which aren't in | ||||
// the form "<string@domain.tld>"; this is also required by RFC 2822, | // the form "<string@domain.tld>"; this is also required by RFC 2822, | ||||
// although some clients are more liberal in what they accept. | // although some clients are more liberal in what they accept. | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | public function newDefaultEmailAddress() { | ||||
if (!strlen($raw_address)) { | if (!strlen($raw_address)) { | ||||
$domain = $this->newMailDomain(); | $domain = $this->newMailDomain(); | ||||
$raw_address = "noreply@{$domain}"; | $raw_address = "noreply@{$domain}"; | ||||
} | } | ||||
$address = new PhutilEmailAddress($raw_address); | $address = new PhutilEmailAddress($raw_address); | ||||
if (!strlen($address->getDisplayName())) { | if (!phutil_nonempty_string($address->getDisplayName())) { | ||||
$address->setDisplayName(pht('Phabricator')); | $address->setDisplayName(PlatformSymbols::getPlatformServerName()); | ||||
} | } | ||||
return $address; | return $address; | ||||
} | } | ||||
public function newVoidEmailAddress() { | public function newVoidEmailAddress() { | ||||
return $this->newDefaultEmailAddress(); | return $this->newDefaultEmailAddress(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |