1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +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:
epriestley 2013-12-12 10:59:28 -08:00
parent d846f6508b
commit 7f45824984
3 changed files with 40 additions and 3 deletions

View file

@ -1,14 +1,37 @@
#!/usr/bin/env 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) {
$_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;
}

View file

@ -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());
}
}
}

View file

@ -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,