Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing attachments using gmail contextual gadgets

I'd like to save an email, along with attachments, from Gmail (Google Apps) to another database for CRM-like functionality. However, according to the docs, "Extractors can not read email attachments". My question: Is it possible to somehow use some type of identifier from the email (such as EmailTimeExtractor) and use that to pull the attachments using IMAP? I'm not very familiar with contextual gadgets yet and just wanted to know if what I'm trying to do is possible before diving in too far!

like image 734
Abdullah Jibaly Avatar asked Nov 15 '22 09:11

Abdullah Jibaly


1 Answers

If you use a standard imap client to pull the email down you'll get the attachment. It'll be one of the parts. Psuedo code:

email = new->email_object();
remote_mailbox = new->imap_object_creator(username, password, ...)

while (email = remote_mailbox->download_next_email) {  // this downloads the next email
  foreach part_type (email->parts->next) {    // this iterates over the parts of the email
    if( part_type == 'attachment' )  {  // not sure if this is it exactly, but you'll find it in the mime-type
      //hooray!  you've found an attachment.  do what you will with it
    }
  }
}

When I was doing this I was writing it in Perl so I used the MIME::Tools suite to hold the email and IMAP::Client as my imap client. But any language should have common objects available to represent an IMAP connection and an email.

like image 98
coffeepac Avatar answered Dec 16 '22 21:12

coffeepac