SendMail.php 19.7 KB
Newer Older
1
2
3
4
5
6
<?php

namespace qfq;

//use qfq;

7
require_once(__DIR__ . '/../Constants.php');
8
require_once(__DIR__ . '/../database/Database.php');
9
require_once(__DIR__ . '/../store/Store.php');
10
require_once(__DIR__ . '/../report/Download.php');
11
require_once(__DIR__ . '/../helper/Sanitize.php');
12
require_once(__DIR__ . '/../helper/HelperFile.php');
13
require_once(__DIR__ . '/../helper/Support.php');
14

15
const SENDMAIL_HTML_TOKEN = '<html>';
16

17
18
19
20
/**
 * Class SendMail
 * @package qfq
 */
21
class SendMail {
22

23
24
25
26
27
    /**
     * @var Store
     */
    private $store = null;

28
    /**
29
30
     * Sends a mail as specified in $mailarr.
     * If there is no receiver specified as 'TO': no mail is sent. This is ok and no error.
31
     * Logs every send mail as a record in table `MailLog`. Additionally a `grId`, `xId` , `xId2` and `xId3`  can be specified
32
     * to assign the log entry to a specific action.
33
     * The log record also contains some information who/where generates the mail (form/formelement or QFQ query).
Carsten  Rose's avatar
Carsten Rose committed
34
     *
35
     * @throws CodeException
36
     * @throws UserFormException
37
     * @throws UserReportException
38
     */
39
40
41
42
43
44
45
    public function __construct() {

        $this->store = Store::getInstance('');
    }


    /**
46
     * @param array $mailConfig
47
48
     * @throws CodeException
     * @throws DbException
49
     * @throws DownloadException
50
     * @throws UserFormException
51
     * @throws UserReportException
52
53
54
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
55
56
     */
    public function process(array $mailConfig) {
57

58
        // If there is no 'Receiver': do not send a mail.
59
        if (!isset($mailConfig[SENDMAIL_TOKEN_RECEIVER]) || $mailConfig[SENDMAIL_TOKEN_RECEIVER] === '') {
60
61
62
            return;
        }

63
64
        if ($mailConfig[SENDMAIL_TOKEN_SENDER] === '' || $mailConfig[SENDMAIL_TOKEN_SUBJECT] === '' || $mailConfig[SENDMAIL_TOKEN_BODY] === '') {
            throw new UserFormException("Error sendmail missing one of: sender, subject or body", ERROR_SENDMAIL_MISSING_VALUE);
65
66
        }

67
68
        $redirectAllMail = $this->store->getVar(SYSTEM_REDIRECT_ALL_MAIL_TO, STORE_SYSTEM);

69
        if (!empty($redirectAllMail)) {
70

Carsten  Rose's avatar
Carsten Rose committed
71
            $addBody = "All QFQ outgoing mails are caught and redirected to you." . PHP_EOL . "Original receiver are ..." . PHP_EOL;
72
73
74
            $addBody .= 'TO: ' . $mailConfig[SENDMAIL_TOKEN_RECEIVER] . PHP_EOL;
            $addBody .= 'CC: ' . $mailConfig[SENDMAIL_TOKEN_RECEIVER_CC] . PHP_EOL;
            $addBody .= 'BCC: ' . $mailConfig[SENDMAIL_TOKEN_RECEIVER_BCC] . PHP_EOL;
75
            $addBody .= 'SENDER: ' . $mailConfig[SENDMAIL_TOKEN_SENDER] . PHP_EOL;
76
77
            $addBody .= PHP_EOL . "==========================================" . PHP_EOL . PHP_EOL;

78
79
80
81
82
            // Check if the given body is a HTML body.
            if (isset($mailConfig[SENDMAIL_TOKEN_BODY_MODE]) && $mailConfig[SENDMAIL_TOKEN_BODY_MODE] === SENDMAIL_TOKEN_BODY_MODE_HTML) {
                $addBody = str_replace(PHP_EOL, '<br>', $addBody);
            }

83
            $mailConfig[SENDMAIL_TOKEN_BODY] = $addBody . $mailConfig[SENDMAIL_TOKEN_BODY];
84

85
86
87
            $mailConfig[SENDMAIL_TOKEN_RECEIVER] = $redirectAllMail;
            $mailConfig[SENDMAIL_TOKEN_RECEIVER_CC] = '';
            $mailConfig[SENDMAIL_TOKEN_RECEIVER_BCC] = '';
88
            $mailConfig[SENDMAIL_TOKEN_SENDER] = $redirectAllMail;
89
90
        }

91
92
93
94
95
96
97
98
99
100
101
102
        $mailConfig = $this->setDefault($mailConfig);

        $logAttachments = $this->sendEmail($mailConfig);
        $this->mailLog($mailConfig, $logAttachments);
    }

    /**
     * @param array $mailConfig
     * @return array
     */
    private function setDefault(array $mailConfig) {

103
104
        if (empty($mailConfig[SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT]) || $mailConfig[SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT] === '') {
            $mailConfig[SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT] = 'on';
105
106
        }

107
        // Subject
108
109
110
111
        if (empty($mailConfig[SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY]) || $mailConfig[SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY] !== MODE_ENCODE) {
            $mailConfig[SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY] = MODE_DECODE;
        }

112
        // Body
113
114
115
116
117
        if (empty($mailConfig[SENDMAIL_TOKEN_BODY_HTML_ENTITY]) || $mailConfig[SENDMAIL_TOKEN_BODY_HTML_ENTITY] !== MODE_ENCODE) {
            $mailConfig[SENDMAIL_TOKEN_BODY_HTML_ENTITY] = MODE_DECODE;
        }

        return $mailConfig;
118
119
120
121
    }

    /**
     * Use the programm 'sendEmail' - http://caspian.dotconf.net/menu/Software/SendEmail
122
     * Body and Subject is UTF8 encoded. Append attachments with '-a <file>'.
123
124
     *
     * @param array $mailConfig
125
     * @return string
126
     * @throws CodeException
Carsten  Rose's avatar
Carsten Rose committed
127
     * @throws DbException
Carsten  Rose's avatar
Carsten Rose committed
128
     * @throws DownloadException
129
     * @throws UserFormException
130
     * @throws UserReportException
131
132
133
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
134
135
136
     */
    private function sendEmail(array $mailConfig) {
        $args = array();
137
        $attachments = array();
138
        $cmdAttachments = '';
139

140
141
142
        $mailConfig[SENDMAIL_TOKEN_SUBJECT] = Support::htmlEntityEncodeDecode($mailConfig[SENDMAIL_TOKEN_SUBJECT_HTML_ENTITY], $mailConfig[SENDMAIL_TOKEN_SUBJECT]);
        $mailConfig[SENDMAIL_TOKEN_BODY] = Support::htmlEntityEncodeDecode($mailConfig[SENDMAIL_TOKEN_BODY_HTML_ENTITY], $mailConfig[SENDMAIL_TOKEN_BODY]);

143
144
145
146
        if (isset($mailConfig[SENDMAIL_TOKEN_BODY_MODE]) && $mailConfig[SENDMAIL_TOKEN_BODY_MODE] === SENDMAIL_TOKEN_BODY_MODE_HTML) {
            $mailConfig[SENDMAIL_TOKEN_BODY] = Support::wrapTag(SENDMAIL_HTML_TOKEN, $mailConfig[SENDMAIL_TOKEN_BODY]);
        }

147
        foreach ($mailConfig as $key => $value) {
148
149
150
            if (is_array($value)) {
                continue;
            }
151
            if ($key != SENDMAIL_TOKEN_SUBJECT) { // do not escape double ticks in subject - this breaks the UTF8 encoding later
152
153
                $mailConfig[$key] = Support::escapeDoubleTick($value);
            }
154
155
        }

156
157
        $args[] = '-f "' . $mailConfig[SENDMAIL_TOKEN_SENDER] . '"';
        $args[] = '-t "' . $mailConfig[SENDMAIL_TOKEN_RECEIVER] . '"';
158
159
160
161
162
163
164
        $args[] = '-o message-charset="utf-8"';

        $logFile = $this->store->getVar(SYSTEM_MAIL_LOG, STORE_SYSTEM);
        if ($logFile != '' && $logFile !== false) {
            $args[] = '-l "' . $logFile . '"';;
        }

165
        if (!empty($mailConfig[SENDMAIL_TOKEN_RECEIVER_CC])) {
166
            $args[] = '-cc "' . $mailConfig[SENDMAIL_TOKEN_RECEIVER_CC] . '"';
167
168
        }

169
        if (!empty($mailConfig[SENDMAIL_TOKEN_RECEIVER_BCC])) {
Carsten  Rose's avatar
Carsten Rose committed
170
            $args[] = '-bcc "' . $mailConfig[SENDMAIL_TOKEN_RECEIVER_BCC] . '"';
171
172
        }

173
        if (!empty($mailConfig[SENDMAIL_TOKEN_SUBJECT])) {
174

175
176
            // The subject needs to be encoded to UTF-8 separately - https://stackoverflow.com/questions/4389676/email-from-php-has-broken-subject-header-encoding/27648245#27648245
            $preferences = ["scheme" => "Q", "input-charset" => "UTF-8", "output-charset" => "UTF-8"];
177
            $encodedSubject = iconv_mime_encode("Subject", $mailConfig[SENDMAIL_TOKEN_SUBJECT], $preferences);
178
179
            $encodedSubject = substr($encodedSubject, 9); // remove 'Subject: '

180
181
            $encodedSubject = Support::escapeDoubleTick($encodedSubject); // now, escape double ticks.

182
183
184
            $args[] = '-u "' . $encodedSubject . '"';;
        }

185
        if (!empty($mailConfig[SENDMAIL_TOKEN_BODY])) {
186

187
            $args[] = '-m "' . $mailConfig[SENDMAIL_TOKEN_BODY] . '"';;
188
189
        }

190
191
        if (!empty($mailConfig[SENDMAIL_TOKEN_REPLY_TO])) {
            $args[] = '-o reply-to="' . $mailConfig[SENDMAIL_TOKEN_REPLY_TO] . '"';;
192
193
        }

194
        if ($mailConfig[SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT] === 'on') {
195
196
197
            $args[] = '-o message-header="Auto-Submitted: auto-send"';
        }

198
199
        if (!empty($mailConfig[SENDMAIL_TOKEN_ATTACHMENT])) {
            $attachments = $this->attachmentsBuild($mailConfig[SENDMAIL_TOKEN_ATTACHMENT]);
200
            if (!empty($attachments)) {
201
202
                $cmdAttachments = '-a ' . implode(' -a ', $attachments);
                $args[] = $cmdAttachments;
203
            }
204
205
        }

206
207
        if (!empty($mailConfig[SENDMAIL_TOKEN_HEADER])) {
            $args[] = '-o message-header="' . $mailConfig[SENDMAIL_TOKEN_HEADER] . '"';
208
209
210
211
212
213
214
215
216
217
218
219
        }

        $sendEmail = $this->store->getVar(SYSTEM_SEND_E_MAIL, STORE_SYSTEM);
        if (empty($sendEmail)) {
            throw new UserFormException("Missing 'sendEmail'", ERROR_SENDMAIL);
        }

        $sendEmailOptions = $this->store->getVar(SYSTEM_SEND_E_MAIL_OPTIONS, STORE_SYSTEM);
        if (!empty($sendEmailOptions)) {
            $args[] = $sendEmailOptions;
        }

220
        OnArray::arrayEscapeshellarg($args);
221
        $cmd = $sendEmail . ' ' . implode(' ', $args);
222
        $cmd = str_replace('`', '\`', $cmd); // escape backticks (escapeshellcmd would be too thorough)
223
224

        exec($cmd, $arr, $rc);
225

226
        if ($rc != 0) {
227
            // After first installation of QFQ extension, the PERL script is not executable: is this the problem here?
228
229
230
231
232
233
234
            $perms = fileperms($sendEmail);
            if (!($perms & 0x0040)) {
                chmod($sendEmail, 0755);
                exec($cmd, $arr, $rc); // Give it a second try.
            }

            if ($rc != 0) {
235
                $output = $rc . " - " . implode('<br>', $arr) . " - " . $cmd;
236
237
238
                throw new UserFormException("Error sendmail failed: " . $output, ERROR_SENDMAIL);
            }
        }
239

240
        HelperFile::cleanTempFiles($attachments);
241

242
        return $cmdAttachments;
243
    }
244

245

246
    /**
247
     * Creates a new MailLog Record based on $mailArr / $header.
248
     *
249
     * @param array $mailConfig
Carsten  Rose's avatar
Carsten Rose committed
250
     *
251
     * @param string $attachmentsLine
252
253
     * @throws CodeException
     * @throws DbException
254
     * @throws UserFormException
Carsten  Rose's avatar
Carsten Rose committed
255
     * @throws UserReportException
256
     */
257
    private function mailLog(array $mailConfig, $attachmentsLine = '') {
258

259
        $log = array();
260

261
262
263
        $header = 'OoO:' . $mailConfig[SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT];
        if (!empty($mailConfig[SENDMAIL_TOKEN_HEADER])) {
            $header .= PHP_EOL . 'Custom: ' . $mailConfig[SENDMAIL_TOKEN_HEADER];
264
        }
265
266
        if (!empty($mailConfig[SENDMAIL_TOKEN_ATTACHMENT])) {
            $header .= PHP_EOL . 'Attachment: ' . $mailConfig[SENDMAIL_TOKEN_ATTACHMENT];
267
268
        }

269
        // Log
270
271
272
273
        $log[] = $mailConfig[SENDMAIL_TOKEN_RECEIVER];
        $log[] = $mailConfig[SENDMAIL_TOKEN_SENDER];
        $log[] = $mailConfig[SENDMAIL_TOKEN_SUBJECT];
        $log[] = $mailConfig[SENDMAIL_TOKEN_BODY];
274
        $log[] = $header;
275
        $log[] = $attachmentsLine;
276
277
278
279
280
        $log[] = empty($mailConfig[SENDMAIL_TOKEN_GR_ID]) ? 0 : $mailConfig[SENDMAIL_TOKEN_GR_ID];
        $log[] = empty($mailConfig[SENDMAIL_TOKEN_X_ID]) ? 0 : $mailConfig[SENDMAIL_TOKEN_X_ID];
        $log[] = empty($mailConfig[SENDMAIL_TOKEN_X_ID2]) ? 0 : $mailConfig[SENDMAIL_TOKEN_X_ID2];
        $log[] = empty($mailConfig[SENDMAIL_TOKEN_X_ID3]) ? 0 : $mailConfig[SENDMAIL_TOKEN_X_ID3];
        $log[] = empty($mailConfig[SENDMAIL_TOKEN_SRC]) ? 0 : $mailConfig[SENDMAIL_TOKEN_SRC];
281

282
        $db = new Database();
283
        $db->sql('INSERT INTO MailLog (`receiver`, `sender`, `subject`, `body`, `header`, `attach`, `grId`, `xId`, `xId2`, `xId3`, `src`, `modified`, `created`) VALUES ( ?, ? , ? , ? ,?, ?, ? ,?, ?, ?, ?, NOW(), NOW() )', ROW_REGULAR, $log);
284

285
    }
286
287

    /**
288
289
290
291
     *
     * @param array $attachments Array of attachments. Per attachment, different & multiple sources are possible.
     *              [ [ 0 -> 'F:/etc/hostname' ],
     *                [ 0 -> 'u:http://nzz.ch', 1 -> 'd:nzz.pdf' ],
292
     *                [ 0 -> 'p:id=detailPerson&form=Person&r=1&_sip=1', 1 -> 'F:/etc/hostname'  ]
293
294
     *                [ 0 -> 'd:all.pdf', 1 -> 'U:?id=detailPerson&form=Person&r=1&_sip=1', 2 -> 'F:/etc/hostname'  ] ]
     * @return array Array of filenames. Those files has to be deleted later, if they are temporary files.
295
     * @throws CodeException
296
     * @throws DbException
297
298
     * @throws DownloadException
     * @throws UserFormException
299
     * @throws UserReportException
300
301
302
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
303
304
305
     */
    private function attachmentsBuild(array $attachments) {
        $files = array();
306
307
        $download = new Download();
        $tmpDir = sys_get_temp_dir();
308

309
        // Several attachments are possible. Process one by one.
310
        foreach ($attachments as $attach) {
311
312
            $vars = array();

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
            // Extract Filename
            $exportFilename = '';
            $downloadMode = '';

            // Per attachment: extract 'mode','filename'. Leave the 'sources' untouched.
            foreach ($attach as $key => $element) {
                $token = $element[0];
                switch ($token) {

                    case SENDMAIL_TOKEN_DOWNLOAD_FILENAME:
                        $exportFilename = substr($element, 2);
                        unset($attach[$key]);
                        break;

                    case SENDMAIL_TOKEN_DOWNLOAD_MODE:
                        $downloadMode = substr($element, 2);
                        unset($attach[$key]);
                        break;

                    case SENDMAIL_TOKEN_ATTACHMENT_FILE:
                        if ($downloadMode == '') { // Set only if not explicit given.
                            $downloadMode = DOWNLOAD_MODE_FILE;
                        }
                        break;

                    case SENDMAIL_TOKEN_ATTACHMENT_URL:
339
340
                    case SENDMAIL_TOKEN_ATTACHMENT_URL_PARAM:
                    case SENDMAIL_TOKEN_ATTACHMENT_PAGE:
341
342
343
344
345
346
347
348
349
350
351
352
353
                        if ($downloadMode == '') { // Set only if not explicit given.
                            $downloadMode = DOWNLOAD_MODE_PDF;
                        }
                        break;

                    default:
                        throw new UserReportException('Unknown token in _sendmail: ' . $token, ERROR_UNKNOWN_TOKEN);
                        break;
                }
            }

            $vars[SIP_DOWNLOAD_PARAMETER] = implode(PARAM_DELIMITER, $attach);
            $vars[DOWNLOAD_MODE] = (count($attach) > 1) ? DOWNLOAD_MODE_PDF : $downloadMode;
354

355
            $file = $download->process($vars, OUTPUT_MODE_FILE);
356

357
            if (empty($exportFilename) && HelperFile::isQfqTemp($file)) {
358

359
360
361
                $exportFilename = DOWNLOAD_OUTPUT_FILENAME;
                if ($downloadMode == DOWNLOAD_MODE_PDF) {
                    $exportFilename .= '.pdf';
362
                }
363
364
365
366
367
368
369
370
371
372
373
374
375
376
            }

            // In case an exportFilename is given: move/rename it, if it is necessary.
            if (!empty($exportFilename)) {

                $exportFilename = Sanitize::safeFilename($exportFilename, true);

                $dir = HelperFile::mktempdir(); // Attachments might have the same filename - create one directory per attachment, to ensure same filenames do not conflict.
                $exportFilename = $dir . '/' . $exportFilename;

                if (HelperFile::isQfqTemp($file)) {
                    rename($file, $exportFilename);
                } else {
                    copy($file, $exportFilename);
377
                }
378
                $file = $exportFilename;
379
            }
380
            $files[] = $file;
381
        }
382
383

        return $files;
384
    }
385
386
387
388


    /**
     * Convert a token based sendMail string into an array.
389
     * - Each attachment (single file or multiple concatenated files) is an array in the array.
390
391
392
393
394
395
396
     *
     * @param string $data E.g.: 't:john@doe.com|f:jane@miller.com|s:Latest|b:Dear John ...'
     * @return array
     * @throws UserFormException
     */
    public function parseStringToArray($data) {

397
        $args = array();
398
399
400
401
402
403
        $attachment = array();

        $flagConcat = false;
        $flagSource = false;
        $flagFilename = false;

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
        $convertToShorthandToken = [
            SENDMAIL_TOKEN_RECEIVER_LONG => SENDMAIL_TOKEN_RECEIVER,
            SENDMAIL_TOKEN_SENDER_LONG => SENDMAIL_TOKEN_SENDER,
            SENDMAIL_TOKEN_SUBJECT_LONG => SENDMAIL_TOKEN_SUBJECT,
            SENDMAIL_TOKEN_BODY_LONG => SENDMAIL_TOKEN_BODY,
            SENDMAIL_TOKEN_RECEIVER_CC_LONG => SENDMAIL_TOKEN_RECEIVER_CC,
            SENDMAIL_TOKEN_RECEIVER_BCC_LONG => SENDMAIL_TOKEN_RECEIVER_BCC,
            SENDMAIL_TOKEN_REPLY_TO_LONG => SENDMAIL_TOKEN_REPLY_TO,
            SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT_LONG => SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT,
            SENDMAIL_TOKEN_GR_ID_LONG => SENDMAIL_TOKEN_GR_ID,
            SENDMAIL_TOKEN_X_ID_LONG => SENDMAIL_TOKEN_X_ID,
            SENDMAIL_TOKEN_X_ID2_LONG => SENDMAIL_TOKEN_X_ID2,
            SENDMAIL_TOKEN_X_ID3_LONG => SENDMAIL_TOKEN_X_ID3,
            SENDMAIL_TOKEN_HEADER_LONG => SENDMAIL_TOKEN_HEADER,
            SENDMAIL_TOKEN_SRC_LONG => SENDMAIL_TOKEN_SRC,
419
            SENDMAIL_TOKEN_BODY_MODE_LONG => SENDMAIL_TOKEN_BODY_MODE,
420
421
        ];

422
        $param = explode(PARAM_DELIMITER, $data);
423

424
        // Iterate over all parameter: use token as key. Collect corresponding attachments arguments in separate array elements.
425
426
427
428
429
430
        foreach ($param AS $line) {

            if (empty($line)) {
                continue;
            }

431
            $tokenAndValue = explode(PARAM_TOKEN_DELIMITER, $line, 2);
432
            if (count($tokenAndValue) < 2 && $tokenAndValue[0] !== SENDMAIL_TOKEN_CONCAT) {
433
                throw new UserFormException('Missing token delimiter "' . PARAM_TOKEN_DELIMITER . '" in: ' . $line, ERROR_UNKNOWN_TOKEN);
434
435
            }

436
437
438
439
440
441
442
443
444
445
            $token = $tokenAndValue[0];
            // convert speaking word tokens to shorthand
            if (strlen($token) > 1) {
                $token = strtolower($token); // speaking word tokens are all lowercase
                if (isset($convertToShorthandToken[$token])) {
                    $token = $convertToShorthandToken[$token];
                } else {
                    throw new UserFormException('Unknown token "' . $token . '" in: ' . $line, ERROR_UNKNOWN_TOKEN);
                }
            }
446

447
448
449
            // Check for deprecated token.
            if ($token == SENDMAIL_TOKEN_ATTACHMENT_FILE_DEPRECATED) {
                throw new UserFormException('Sendmail: Option "a:" is deprecated, please use "' . SENDMAIL_TOKEN_ATTACHMENT_FILE . '" instead', ERROR_UNKNOWN_TOKEN);
450
451
            }

452
            switch ($token) {
453
454
455
                case SENDMAIL_TOKEN_CONCAT:
                    $flagConcat = true;
                    if (!empty($attachment)) {
456
                        $args[SENDMAIL_TOKEN_ATTACHMENT][] = $attachment;
457
458
459
460
461
462
                        $attachment = array();
                    }
                    break;

                case SENDMAIL_TOKEN_ATTACHMENT_FILE:
                case SENDMAIL_TOKEN_ATTACHMENT_URL:
463
464
                case SENDMAIL_TOKEN_ATTACHMENT_URL_PARAM:
                case SENDMAIL_TOKEN_ATTACHMENT_PAGE:
465
                    if ($flagSource && !$flagConcat) {
466
                        $args[SENDMAIL_TOKEN_ATTACHMENT][] = $attachment;
467
468
469
470
471
472
473
474
475
                        $attachment = array();
                        $flagFilename = false;
                    }
                    $flagSource = true;
                    $attachment[] = $line;
                    break;

                case SENDMAIL_TOKEN_DOWNLOAD_FILENAME:
                    if ($flagFilename && !$flagConcat) {
476
                        $args[SENDMAIL_TOKEN_ATTACHMENT][] = $attachment;
477
478
479
480
481
482
483
484
                        $attachment = array();
                        $flagSource = false;
                    }
                    $flagFilename = true;
                    $attachment[] = $line;
                    break;

                default:
485
                    $args[$token] = $tokenAndValue[1];
486
487
488
489
490
                    break;
            }
        }

        if (!empty($attachment)) {
491
            $args[SENDMAIL_TOKEN_ATTACHMENT][] = $attachment;
492
493
        }

494
        return ($args);
495
496
    }

497
}