Change email subject



  • I know that one can mess around with the email templates, but I see no way to change the subject of the email.
    Like:

    [sitename #topic_id] topic_name
    

    I need to include the topic id in the subject because I need to parse the subject ( postfix forward pointing to a Yii console controller, if you must know) - do I need to mess around in the source code?

    Edit:
    I am implementing reply by email, btw.
    And since I am a PHP developer, I am using the api and dirty tricks ;)



  • I also do know that I can grab the topic id from the URL - that thought came to me just now :p - but it is easier to just regex the subject.


  • Admin

    Emailer fires:

    Plugins.fireHook('filter:email.modify', data, next);

    Listen to that hook, modify subject in data, voila.



  • /* puts nodejs on list of stuff to learn .. */

    Ok, I will perhaps try and look into that ;)



  • I just did a stupidly simple (stupid?) plugin but it does not seem to do much :)

    (function(module) {
        "use strict";
    
        var autoreplyit = {};
    
        autoreplyit.filter = function(data) {
            data.subject = data.subject + ' #' + data.pid;
        };
    
        module.exports = autoreplyit;
    }(module));
    
    {
        "id": "nodebb-plugin-autoreplyit",
        "name": "NodeBB Autoreply email subject changer",
        "description": "NodeBB Plugin that changes the email subject field to include the topic id.",
        "url": "https://github.com/jacmoe/nodebb-plugin-autoreplyit",
        "library": "./library.js",
        "hooks": [
            { "hook": "filter:email.modify", "method": "filter" }
        ]
    }
    

  • Admin

    Check to see that autoreplyit.filter is executed (maybe a console.log?)

    Your filter will need a callback:

    autoreplyit.filter = function(data, callback) {
      data.subject = data.subject + ' #' + data.pid;
      callback(null, data);
    };
    
    


  • It works :)
    0_1450084954543_nodebb5.jpg

    (function(module) {
        "use strict";
    
        var autoreplyit = {};
    
        autoreplyit.filter = function(data, callback) {
            var re = /http:\/\/nodebbjacmoe-jacmoe\.rhcloud\.com\/topic\/(\d+)/;
            var str = data.plaintext;
            var found = str.match(re);
            data.subject = data.subject + ' #' + found[1];
            callback(null, data);
        };
    
        module.exports = autoreplyit;
    }(module));
    

    Totally hard-coded, of course :p

    Edit:
    I am fully aware that it is only a matter of time before a kind soul points out to me that I can easily get the site url from a dark corner of the API - but, hey: it works.
    Now the receiving PHP script can grab the topic id and make sure that it is sent to the right place.



  • Thanks a lot @julian :)


  • Admin

    @Jacob-Moen Hey, if it works, it works!

    Now you've written a NodeBB plugin 😄



  • I threw in an if(found) just in case - but I am always amazed by how little code is required.
    That seem to happen a lot with Node.js and a well written software entitled NodeBB 👍


Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.