Overview
Comment:Add bounce handling API
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | emails
Files: files | file ages | folders
SHA3-256: 25bd88c9696134384e0a2e5ad0c339b6d1e3e57c22b29b37ebb002341a18f910
User & Date: bohwaz on 2022-06-02 00:21:27
Other Links: branch diff | manifest | tags
Context
2022-06-02
01:05
Fix reference to unset property in Email check-in: 222280b24e user: bohwaz tags: emails
00:21
Add bounce handling API check-in: 25bd88c969 user: bohwaz tags: emails
00:00
Remove unused 'use' statement check-in: 143953387e user: bohwaz tags: emails
Changes

Modified src/config.dist.php from [4dc5196bb5] to [f1c00bfd4c].

399
400
401
402
403
404
405
























406
407
408
409
410
411
412
 * permettant de traiter les mails reçus à cette adresse.
 *
 * Défaut : null
 */

//const MAIL_RETURN_PATH = 'returns@monserveur.com';

























/**
 * Couleur primaire de l'interface admin par défaut
 * (peut être personnalisée dans la configuration)
 *
 * Défaut : #9c4f15
 */








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
 * permettant de traiter les mails reçus à cette adresse.
 *
 * Défaut : null
 */

//const MAIL_RETURN_PATH = 'returns@monserveur.com';

/**
 * Mot de passe pour l'accès à l'API permettant de gérer les mails d'erreur
 * (voir MAIL_RETURN_PATH)
 *
 * Cette adresse HTTP permet de gérer un bounce email reçu en POST.
 * C'est utile si votre serveur de mail est capable de faire une requête HTTP
 * à la réception d'un message.
 *
 * La requête bounce doit contenir un paramètre "message", contenant l'intégralité
 * de l'email avec les entêtes.
 *
 * Si on définit 'abcd' ici, il faudra faire une requête comme ceci :
 * curl -F 'message=@/tmp/message.eml' https://bounce:abcd@monasso.com/admin/handle_bounce.php
 *
 * En alternative le serveur de mail peut aussi appeler le script
 * 'scripts/handle_bounce.php'
 *
 * Défaut : null (l'API handlebounce est désactivée)
 *
 * @type string|null
 */

//const MAIL_BOUNCE_PASSWORD = null;

/**
 * Couleur primaire de l'interface admin par défaut
 * (peut être personnalisée dans la configuration)
 *
 * Défaut : #9c4f15
 */

Modified src/include/init.php from [4b7b923e75] to [765d3e03be].

197
198
199
200
201
202
203

204
205
206
207
208
209
210
	'ENABLE_XSENDFILE'      => false,
	'SMTP_HOST'             => false,
	'SMTP_USER'             => null,
	'SMTP_PASSWORD'         => null,
	'SMTP_PORT'             => 587,
	'SMTP_SECURITY'         => 'STARTTLS',
	'MAIL_RETURN_PATH'      => null,

	'ADMIN_URL'             => WWW_URL . 'admin/',
	'NTP_SERVER'            => 'fr.pool.ntp.org',
	'ADMIN_COLOR1'          => '#9c4f15',
	'ADMIN_COLOR2'          => '#d98628',
	'FILE_STORAGE_BACKEND'  => 'SQLite',
	'FILE_STORAGE_CONFIG'   => null,
	'FILE_STORAGE_QUOTA'    => null,







>







197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
	'ENABLE_XSENDFILE'      => false,
	'SMTP_HOST'             => false,
	'SMTP_USER'             => null,
	'SMTP_PASSWORD'         => null,
	'SMTP_PORT'             => 587,
	'SMTP_SECURITY'         => 'STARTTLS',
	'MAIL_RETURN_PATH'      => null,
	'MAIL_BOUNCE_PASSWORD'  => null,
	'ADMIN_URL'             => WWW_URL . 'admin/',
	'NTP_SERVER'            => 'fr.pool.ntp.org',
	'ADMIN_COLOR1'          => '#9c4f15',
	'ADMIN_COLOR2'          => '#d98628',
	'FILE_STORAGE_BACKEND'  => 'SQLite',
	'FILE_STORAGE_CONFIG'   => null,
	'FILE_STORAGE_QUOTA'    => null,

Modified src/include/lib/Garradin/Users/Emails.php from [c21f4d6c91] to [b59cf0e598].

459
460
461
462
463
464
465




466
467
468
469
470
471
472
	 */
	static public function handleBounce(string $raw_message): ?array
	{
		$message = new Mail_Message;
		$message->parse($raw_message);

		$return = $message->identifyBounce();





		if ($return['type'] == 'autoreply') {
			// Ignore auto-responders
			return $return;
		}
		elseif ($return['type'] == 'genuine') {
			// Forward emails that are not automatic to the organization email







>
>
>
>







459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
	 */
	static public function handleBounce(string $raw_message): ?array
	{
		$message = new Mail_Message;
		$message->parse($raw_message);

		$return = $message->identifyBounce();

		if (!$return) {
			return null;
		}

		if ($return['type'] == 'autoreply') {
			// Ignore auto-responders
			return $return;
		}
		elseif ($return['type'] == 'genuine') {
			// Forward emails that are not automatic to the organization email

Added src/www/admin/handle_bounce.php version [250e0cfa82].























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

namespace Garradin;

use Garradin\Users\Emails;

require_once __DIR__ . '/../../include/init.php';

function error(int $http_code, string $message)
{
	$http_statuses = [
		202 => 'Accepted',
		400 => 'Bad Request',
		401 => 'Unauthorized',
		402 => 'Payment Required',
		403 => 'Forbidden',
		404 => 'Not Found',
		405 => 'Method Not Allowed',
		406 => 'Not Acceptable',
		407 => 'Proxy Authentication Required',
		408 => 'Request Timeout',
		409 => 'Conflict',
	];

	header(sprintf('%s %d %s', $_SERVER['SERVER_PROTOCOL'], $http_code, $http_statuses[$http_code]), true, $http_code);
	echo $message . PHP_EOL;
	exit;
}

if (empty(MAIL_BOUNCE_PASSWORD) || empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW'])
	|| $_SERVER['PHP_AUTH_USER'] != 'bounce' || $_SERVER['PHP_AUTH_PW'] != MAIL_BOUNCE_PASSWORD)
{
	error(403, 'Invalid credentials');
}

if (empty($_POST['message']))
{
	error(400, 'Missing or invalid required parameters');
}

Emails::handleBounce($_POST['message']);

error(202, 'OK');