Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Email plugin

Hello,

I'm a researcher and would like to create an extension that will fetch users email (content and attachments) when the user clicks "send button" and delay/stop sending process based on content. The idea being that I will be doing some statistical analysis on the email and its content for the benefit of the user through Natural language processing techniques. Similar to spell-check but will be looking at sentence structure, grammar and several other text features.

While implementing this I have used the 'email plugin' which works very well to identify gmail login, compose event, viewing a message, send button click event etc. However, I could not find any methods to extract the message body or the attachments. It will be very helpful if you direct me to the right resource.

Thanks
Arjun
2 people have
this question
+1
Reply
  • Hello Arjun,

    Thank you for your question. You appear to have a good working knowledge of the email plugin. Have you tried using the send button click event handlers components parameter? It includes a contentBody property that contains the message body, as follows:
    <code>appAPI.ready(function($) {
    // Load the Email plugin
    var emailHook = appAPI.hooks.register('emails');

    // Register the Send Button click event
    emailHook.addListener('send_button_clicked', function(components) {
    // Do something with the message body
    console.log('Message body::' + components.contentBody);
    });
    });
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited

  • I’m thankful
    Hi Shlomo,

    Thank you very much for a swift reply. I'm enjoying cross rider so far.

    components.contentBody returns 'undefined' and not the content of the message. while components.subject.val() returns the right subject. See below for the code

    emailHook.addListener('send_button_clicked', function(components) {
    console.log('Subject while send button clicked:'+components.subject.val()); //works
    console.log('Message body while send button is clicked::' + components.contentBody); //does not work. returns 'undefined'
    });

    Is there an API to the email plugin? I could not find one in the wiki. Looks like there might be other functions that could be of great use to my project.

    Also, would you kindly suggest a way to fetch the local file path of the attachments that user had added to his/her email? I hope there is an easy way to do this. I'm concerned only about gmail so far if that makes any difference.

    I'm a newbie to the exciting world of browser extension and would appreciate any help.

    Thanks again
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hello Arjun,

    Due to the ever changing Google Mail, it appears that their more recent changes have "broken" that part of the plugin.

    I have reported the issue to the dev team, but it may be awhile before they get a chance to take a look at it.

    However, in the meantime you can work around the issue using jquery to grab the message body as follows:
    <code>appAPI.ready(function($) {
    // Load the Email plugin
    var emailHook = appAPI.hooks.register('emails');

    // Register the Send Button click event
    emailHook.addListener('send_button_clicked', function(components) {
    // Do something with the message body
    console.log('Message::',
    $('div').find('[aria-label="Message Body"]').text() // Message body
    );
    });
    });
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hi Shlomo,

    Once again thank you loads for your suggestion. It works perfectly.

    Any idea on attachments? I'm struggling with that. I looked at gmail's source code but could not find a way. The best I got so far,


    console.log('Val::',$('div').find('[class="dL"]').text());


    which returns only the names of the files attached as

    file1.doc (80K) file2.xlx (127K)


    This is of no use. Is there anyway to get hold of the file itself? Does the email plugin have any inbuilt functions to do this?

    Many thanks in anticipation
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hello Arjun,

    I'm afraid attachments are a much more complex matter and they are not provided for by the Email Plugin.

    However, we suspect that in older browsers Gmail use Flash to upload files (in which case you cannot obtain them at all) and the HTML 5 File API in new browsers in which case you may be able to get a handle to the file using the API.

    If you succeed, feel free to share the code for the benefit of others and I'll pass it on to our dev team to consider for implementation.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • I am putting this question as it is for the same plugin
    I can get editor, subject etc components in current gmail page.
    I want to get/set to,cc,bcc components
    i had seen code from plugin which say :
    components.to.val();
    which is not working.

    Here is my code.

    this.addPanelButton('testing', function(components) {
    var editor = this.getComponent('to');
    alert(editor.val());
    }

    subject and editor working but to,cc not.

    If I set the value myself like editor.val('test@testing.com');
    it will alert test@testing.com.
    but if setting by writing in gmail To part
    it will show NULL

    what can be the problem?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hello Arjun,

    Similarly, the gmail changes have affected this component as well and can be worked around by using jQuery, as follows:
    <code>this.addPanelButton('testing', function(components) { 
    var to = []; $('input[name="to"]').each(function() {to.push($(this).val());});
    }
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • This reply was removed on 2013-10-03.
    see the change log