mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42:41 +01:00
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
This commit is contained in:
parent
d846f6508b
commit
7f45824984
3 changed files with 40 additions and 3 deletions
|
@ -1,14 +1,37 @@
|
||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// NOTE: This script is very oldschool and takes the environment as an argument.
|
||||||
|
// Some day, we could take a shot at cleaning this up.
|
||||||
if ($argc > 1) {
|
if ($argc > 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__)));
|
$root = dirname(dirname(dirname(__FILE__)));
|
||||||
require_once $root.'/scripts/__init_script__.php';
|
require_once $root.'/scripts/__init_script__.php';
|
||||||
require_once $root.'/externals/mimemailparser/MimeMailParser.class.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 = new MimeMailParser();
|
||||||
$parser->setText(file_get_contents('php://stdin'));
|
$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['subject'] = iconv_mime_decode($headers['subject'], 0, "UTF-8");
|
||||||
$headers['from'] = iconv_mime_decode($headers['from'], 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 = new PhabricatorMetaMTAReceivedMail();
|
||||||
$received->setHeaders($headers);
|
$received->setHeaders($headers);
|
||||||
$received->setBodies(array(
|
$received->setBodies(array(
|
||||||
|
@ -62,6 +89,8 @@ try {
|
||||||
$received
|
$received
|
||||||
->setMessage('EXCEPTION: '.$e->getMessage())
|
->setMessage('EXCEPTION: '.$e->getMessage())
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,13 +53,15 @@ final class ConpherenceCreateThreadMailReceiver
|
||||||
$phids = mpull($users, 'getPHID');
|
$phids = mpull($users, 'getPHID');
|
||||||
|
|
||||||
$conpherence = id(new ConpherenceReplyHandler())
|
$conpherence = id(new ConpherenceReplyHandler())
|
||||||
->setMailReceiver(new ConpherenceThread())
|
->setMailReceiver(ConpherenceThread::initializeNewThread($sender))
|
||||||
->setMailAddedParticipantPHIDs($phids)
|
->setMailAddedParticipantPHIDs($phids)
|
||||||
->setActor($sender)
|
->setActor($sender)
|
||||||
->setExcludeMailRecipientPHIDs($mail->loadExcludeMailRecipientPHIDs())
|
->setExcludeMailRecipientPHIDs($mail->loadExcludeMailRecipientPHIDs())
|
||||||
->processEmail($mail);
|
->processEmail($mail);
|
||||||
|
|
||||||
$mail->setRelatedPHID($conpherence->getPHID());
|
if ($conpherence) {
|
||||||
|
$mail->setRelatedPHID($conpherence->getPHID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,12 @@ final class ConpherenceThread extends ConpherenceDAO
|
||||||
private $widgetData = self::ATTACHABLE;
|
private $widgetData = self::ATTACHABLE;
|
||||||
private $images = array();
|
private $images = array();
|
||||||
|
|
||||||
|
public function initializeNewThread(PhabricatorUser $sender) {
|
||||||
|
return id(new ConpherenceThread())
|
||||||
|
->setMessageCount(0)
|
||||||
|
->setTitle('');
|
||||||
|
}
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
self::CONFIG_AUX_PHID => true,
|
self::CONFIG_AUX_PHID => true,
|
||||||
|
|
Loading…
Reference in a new issue