|
1 | 1 | #!/usr/bin/env php
|
2 | 2 | <?php
|
3 | 3 |
|
| 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. |
4 | 6 | 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 | + } |
6 | 13 | }
|
7 | 14 |
|
8 | 15 | $root = dirname(dirname(dirname(__FILE__)));
|
9 | 16 | require_once $root.'/scripts/__init_script__.php';
|
10 | 17 | require_once $root.'/externals/mimemailparser/MimeMailParser.class.php';
|
11 | 18 |
|
| 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 | + |
12 | 35 | $parser = new MimeMailParser();
|
13 | 36 | $parser->setText(file_get_contents('php://stdin'));
|
14 | 37 |
|
|
28 | 51 | $headers['subject'] = iconv_mime_decode($headers['subject'], 0, "UTF-8");
|
29 | 52 | $headers['from'] = iconv_mime_decode($headers['from'], 0, "UTF-8");
|
30 | 53 |
|
| 54 | +if ($args->getArg('process-duplicates')) { |
| 55 | + $headers['message-id'] = Filesystem::readRandomCharacters(64); |
| 56 | +} |
| 57 | + |
31 | 58 | $received = new PhabricatorMetaMTAReceivedMail();
|
32 | 59 | $received->setHeaders($headers);
|
33 | 60 | $received->setBodies(array(
|
|
62 | 89 | $received
|
63 | 90 | ->setMessage('EXCEPTION: '.$e->getMessage())
|
64 | 91 | ->save();
|
| 92 | + |
| 93 | + throw $e; |
65 | 94 | }
|
66 | 95 |
|
67 | 96 |
|
0 commit comments