Last active
September 7, 2015 10:27
-
-
Save pixelpaulaus/8b206f62ee18daa2f87c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports.hook_data = function (next, connection) { | |
| var me = this | |
| var txn = connection.transaction; | |
| connection.transaction.parse_body = 1; // enable mail body parsing | |
| txn.notes.attachment_count = 0; | |
| function start_attachment(connection, ctype, filename, body, stream) { | |
| var txn = connection.transaction; | |
| txn.notes.attachment_count++; | |
| function next() { | |
| if (txn.notes.attachment_count === 0 && txn.notes.attachment_next) { | |
| return txn.notes.attachment_next(); | |
| } | |
| else { | |
| return; | |
| } | |
| } | |
| //do my stuff here | |
| me.loginfo("ATTACHMENT HOOK content-type: "+JSON.stringify(ctype)+" , filename: "+JSON.stringify(filename)); | |
| //end my stuff here | |
| txn.notes.attachment_count--; | |
| return next(); | |
| } | |
| connection.transaction.attachment_hooks( | |
| function (ct, fn, body, stream) { | |
| start_attachment(connection, ct, fn, body, stream) | |
| } | |
| ); | |
| return next(); | |
| } | |
| exports.hook_data_post = function (next, connection) { | |
| var txn = connection.transaction; | |
| if (txn.notes.attachment_count > 0) { | |
| // We still have attachment hooks running | |
| txn.notes.attachment_next = next; | |
| } | |
| else { | |
| next(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment