POST-ing bounce email to a Mediawiki API directly from exim

While moving forward with the BounceHandler extension, I was advised by my mentors to make sure that the bounce emails are directly fed to an API inside the extension, so that no manual queries are required, and its more safe.
An API, with the name foo can be accessed in the URL by http://localhost/mw-core/api.php?action=foo. A POST request with the name bar can be sent by URL http://localhost/mw-core/api.php?action=foo&bar=value
* How to add the new API
In your extension.php, register the new API, named bouncehandler firstly by:

$wgAutoloadClasses['ApiBounceHandler'] = $dir. '/ApiBounceHandler.php';
$wgAPIModules['bouncehandler'] = 'ApiBounceHandler';

* Make exim forward the emails directly to the API. Put this under the appropriate pipe transport.

command = /usr/bin/curl http://localhost/core/core/api.php -d "action=bouncehandler" --data-urlencode "email@-" -o /dev/null

or this can be done in a shell script too. You can direct the command to the shell script.

command = /path/to/script.sh

and in the script.sh

#!/bin/bash
curl -d "action=bouncehandler" --data-urlencode "email@-" http://localhost/core/mw-core/api.php

* Now, on reception of a mail, it gets automatically transferred to the API, with the email as a POST param. The generated POST url will be of the form http://localhost/core/mw-core/api.php?action=bouncehandler&email=the_email
* You can recieve the email POST param in the API by

class ApiBounceHandler extends ApiBase {
	public function execute() {
             $email = $this->getMain()->getVal( 'email' );
        }
}

Yay! further handling of the emails coming up in next post! πŸ™‚ Happy Hacking!

Advertisements

5 thoughts on “POST-ing bounce email to a Mediawiki API directly from exim

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s