Skip to content

Commit 7f45824

Browse files
author
epriestley
committedDec 12, 2013
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
1 parent d846f65 commit 7f45824

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed
 

‎scripts/mail/mail_handler.php

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
11
#!/usr/bin/env php
22
<?php
33

4+
// NOTE: This script is very oldschool and takes the environment as an argument.
5+
// Some day, we could take a shot at cleaning this up.
46
if ($argc > 1) {
5-
$_SERVER['PHABRICATOR_ENV'] = $argv[1];
7+
foreach (array_slice($argv, 1) as $arg) {
8+
if (!preg_match('/^-/', $arg)) {
9+
$_SERVER['PHABRICATOR_ENV'] = $arg;
10+
break;
11+
}
12+
}
613
}
714

815
$root = dirname(dirname(dirname(__FILE__)));
916
require_once $root.'/scripts/__init_script__.php';
1017
require_once $root.'/externals/mimemailparser/MimeMailParser.class.php';
1118

19+
$args = new PhutilArgumentParser($argv);
20+
$args->parseStandardArguments();
21+
$args->parse(
22+
array(
23+
array(
24+
'name' => 'process-duplicates',
25+
'help' => pht(
26+
"Process this message, even if it's a duplicate of another message. ".
27+
"This is mostly useful when debugging issues with mail routing."),
28+
),
29+
array(
30+
'name' => 'env',
31+
'wildcard' => true,
32+
),
33+
));
34+
1235
$parser = new MimeMailParser();
1336
$parser->setText(file_get_contents('php://stdin'));
1437

@@ -28,6 +51,10 @@
2851
$headers['subject'] = iconv_mime_decode($headers['subject'], 0, "UTF-8");
2952
$headers['from'] = iconv_mime_decode($headers['from'], 0, "UTF-8");
3053

54+
if ($args->getArg('process-duplicates')) {
55+
$headers['message-id'] = Filesystem::readRandomCharacters(64);
56+
}
57+
3158
$received = new PhabricatorMetaMTAReceivedMail();
3259
$received->setHeaders($headers);
3360
$received->setBodies(array(
@@ -62,6 +89,8 @@
6289
$received
6390
->setMessage('EXCEPTION: '.$e->getMessage())
6491
->save();
92+
93+
throw $e;
6594
}
6695

6796

‎src/applications/conpherence/mail/ConpherenceCreateThreadMailReceiver.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ protected function processReceivedMail(
5353
$phids = mpull($users, 'getPHID');
5454

5555
$conpherence = id(new ConpherenceReplyHandler())
56-
->setMailReceiver(new ConpherenceThread())
56+
->setMailReceiver(ConpherenceThread::initializeNewThread($sender))
5757
->setMailAddedParticipantPHIDs($phids)
5858
->setActor($sender)
5959
->setExcludeMailRecipientPHIDs($mail->loadExcludeMailRecipientPHIDs())
6060
->processEmail($mail);
6161

62-
$mail->setRelatedPHID($conpherence->getPHID());
62+
if ($conpherence) {
63+
$mail->setRelatedPHID($conpherence->getPHID());
64+
}
6365
}
6466

6567
}

‎src/applications/conpherence/storage/ConpherenceThread.php

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ final class ConpherenceThread extends ConpherenceDAO
1818
private $widgetData = self::ATTACHABLE;
1919
private $images = array();
2020

21+
public function initializeNewThread(PhabricatorUser $sender) {
22+
return id(new ConpherenceThread())
23+
->setMessageCount(0)
24+
->setTitle('');
25+
}
26+
2127
public function getConfiguration() {
2228
return array(
2329
self::CONFIG_AUX_PHID => true,

0 commit comments

Comments
 (0)
Failed to load comments.