From 7f45824984de7f4b0e4ef79684c0716210fe855a Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 12 Dec 2013 10:59:28 -0800 Subject: [PATCH] Fix two issues with creating Conpherence threads via mail on some configurations Summary: Ref T4107. Two issues: - With strict MySQL settings, we try to insert `null` into the non-nullable `messageCount` field. Add an `initializeNew...` method. - If we don't create a new conpherence (for example, because the message body is empty), we fatal on `getPHID()` right now. Also, make this stuff a little easier to test. Test Plan: Used `mail_handler.php` to receive empty conpherence mail, and new-thread conpherence mail. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4107 Differential Revision: https://secure.phabricator.com/D7760 --- scripts/mail/mail_handler.php | 31 ++++++++++++++++++- .../ConpherenceCreateThreadMailReceiver.php | 6 ++-- .../conpherence/storage/ConpherenceThread.php | 6 ++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/scripts/mail/mail_handler.php b/scripts/mail/mail_handler.php index 19e315364d..11d8f1c29f 100755 --- a/scripts/mail/mail_handler.php +++ b/scripts/mail/mail_handler.php @@ -1,14 +1,37 @@ #!/usr/bin/env php 1) { - $_SERVER['PHABRICATOR_ENV'] = $argv[1]; + foreach (array_slice($argv, 1) as $arg) { + if (!preg_match('/^-/', $arg)) { + $_SERVER['PHABRICATOR_ENV'] = $arg; + break; + } + } } $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; require_once $root.'/externals/mimemailparser/MimeMailParser.class.php'; +$args = new PhutilArgumentParser($argv); +$args->parseStandardArguments(); +$args->parse( + array( + array( + 'name' => 'process-duplicates', + 'help' => pht( + "Process this message, even if it's a duplicate of another message. ". + "This is mostly useful when debugging issues with mail routing."), + ), + array( + 'name' => 'env', + 'wildcard' => true, + ), + )); + $parser = new MimeMailParser(); $parser->setText(file_get_contents('php://stdin')); @@ -28,6 +51,10 @@ $headers = $parser->getHeaders(); $headers['subject'] = iconv_mime_decode($headers['subject'], 0, "UTF-8"); $headers['from'] = iconv_mime_decode($headers['from'], 0, "UTF-8"); +if ($args->getArg('process-duplicates')) { + $headers['message-id'] = Filesystem::readRandomCharacters(64); +} + $received = new PhabricatorMetaMTAReceivedMail(); $received->setHeaders($headers); $received->setBodies(array( @@ -62,6 +89,8 @@ try { $received ->setMessage('EXCEPTION: '.$e->getMessage()) ->save(); + + throw $e; } diff --git a/src/applications/conpherence/mail/ConpherenceCreateThreadMailReceiver.php b/src/applications/conpherence/mail/ConpherenceCreateThreadMailReceiver.php index 6e2fa8cd71..aba7adc756 100644 --- a/src/applications/conpherence/mail/ConpherenceCreateThreadMailReceiver.php +++ b/src/applications/conpherence/mail/ConpherenceCreateThreadMailReceiver.php @@ -53,13 +53,15 @@ final class ConpherenceCreateThreadMailReceiver $phids = mpull($users, 'getPHID'); $conpherence = id(new ConpherenceReplyHandler()) - ->setMailReceiver(new ConpherenceThread()) + ->setMailReceiver(ConpherenceThread::initializeNewThread($sender)) ->setMailAddedParticipantPHIDs($phids) ->setActor($sender) ->setExcludeMailRecipientPHIDs($mail->loadExcludeMailRecipientPHIDs()) ->processEmail($mail); - $mail->setRelatedPHID($conpherence->getPHID()); + if ($conpherence) { + $mail->setRelatedPHID($conpherence->getPHID()); + } } } diff --git a/src/applications/conpherence/storage/ConpherenceThread.php b/src/applications/conpherence/storage/ConpherenceThread.php index 3e632fec27..0622f9fa9f 100644 --- a/src/applications/conpherence/storage/ConpherenceThread.php +++ b/src/applications/conpherence/storage/ConpherenceThread.php @@ -18,6 +18,12 @@ final class ConpherenceThread extends ConpherenceDAO private $widgetData = self::ATTACHABLE; private $images = array(); + public function initializeNewThread(PhabricatorUser $sender) { + return id(new ConpherenceThread()) + ->setMessageCount(0) + ->setTitle(''); + } + public function getConfiguration() { return array( self::CONFIG_AUX_PHID => true,