I am working on version 2 of the mailsave module. One of the key aims will be to make it possible to send images, audio and video from your mobile phone to your Drupal site via a multimedia messaging service (MMS).

If you want to join in please could you send a one page picture MMS from your mobile phone to mailsave@stuartandnicola.com. Keep reading to find out why...

When you create an MMS message you can usually send it to an email address rather than another mobile number. What happens when you do this is that you get an email message that has been created by your service provider and has often had extra text and images added to it. Note that using MMS is different to email. Configuring a mobile phone for email can be tricky, but most phones come with MMS ready to go. The trick is that we rely on the service provider to turn our MMS in to an email for us.

For example, when I use my provider (Vodafone UK) I get a result like this which isn't very pretty, and has also acquired a Vodafone logo as an attachment. With a bit of clean up code I can turn the post in to something more like this, which is much more user friendly and doesn't give away my mobile number!

I need some help as I don't have many other samples to compare to at the moment! By getting a few more picture message I can collect some more data! Please include in your message who your provider is (in case they DON'T add it to your message), which country, and your name too if you like! I'm looking to see if there are generic aspects to MMS messages that would allow a common filter, or whether filters need to be on a provider-by-provider basis. Within that, are {provider}-UK messages different to, say, {provider}-France, {provider}-USA etc

Thinking out loud... the actual MMSs could be an interesting project in their own right - if people send pictures of themselves or something from where they live this could become a photo record of the Drupal community!

Privacy note: Your MMS message will probably reveal your mobile number to me. At the moment the module development is being done on a local test server behind a firewall. I will not use your number, post your details to a public site etc, and will delete the messages when the tests are done.

I'll leave the mailbox open until I start getting hit with too much spam! I will then close it and post a message here to say it's no longer in use!

Thanks in advance!

Comments

bajakan’s picture

Sent from Austin, TX! a lovely picture of my monitor reading your article. :9 would have been a pic of me but then someone might stalk me or something cuz I'm dead sexy.

Stuart Greenfield’s picture

Message (and nice picture of your monitor!) received. It looks like filters will need to be customised - Verizon don't add a logo, but they add extra text.

But there is now a module to clean up Verizon USA formatted messages!

The module is very simple, it only took a few minutes to tweak the regex matching.

Thanks again!

Just five more minutes...

www.stuartandnicola.com

barrysampson’s picture

Just sent you a pic of my tidy iMac on an untidy desk. Via T-Mobile UK.

Stuart Greenfield’s picture

Thanks for the sample message. Mailsave now has a T-Mobile filter.

If you don't mind could you send a second message with a longer text portion. There seems to be a section in the message body that is headed Your message but contains nothing but an   while the message title appears to contain what I assume was the body.

It might be that T-Mobile put all the message in the email title. An MMS with more text will help to test this.

For info, T-Mobile emails contain a logo which the filter discards, and lots of CSS and extra content which is now thrown away.

I've uploaded the new snapshot of mailsave with the T-Mobile filter.

The filters are proving very quick and easy to write so I'm pretty pleased with how this is developing!

PS - Desk didn't look too bad to me :-)

________

Just five more minutes...

www.stuartandnicola.com

barrysampson’s picture

I've sent another message. This time it's a Dell on my desk at work (just to show I'm not biased!)

One of my colleagues is just sending you a messgae via O2 UK (this time it's a nice Starbucks mug)!

Stuart Greenfield’s picture

New message received - the T-Mobile filter now picks up the body and title elements of the message, and discards the T-Mobile logo, so incoming messages are reduced to just the "good" content :-)

Thanks for your help on this one - mailsave now has three working filters

  • Vodafone - UK
  • TMobile - UK
  • Verizon - US

________

Just five more minutes...

www.stuartandnicola.com

Stuart Greenfield’s picture

The O2 message is quite different to the others which is curious! It is plain text, rather than HTML, and with no logo.

The message that was sent has no body and no title - is that because that is how the message was written? Or does O2 not send that through in the e-mail?

At the moment the filter therefore rejects all the text and sets a generic title. If the message was sent without these elements then the filter will need a further MMS message for me to be able to see how to intercept the text / title elements.

________

Just five more minutes...

www.stuartandnicola.com

barrysampson’s picture

I think you may have to consider another variable; which phone was it sent from?

The T-Mobile message I sent you came from my HTC S310 (Windows Mobile 5.0). The workflow goes; access camera, take pic, select send, pick MMS, enter email address or number, enter title, enter body text, hit send.

The O2 message came from a Motorola SLVR. That workflow goes; access camera, take pic, select send, pick MMS, enter email address or number, hit send. So there's no option to add a title or body.

When she gets home from work I will borrow my girlfriend's Samsung which is also on O2 and see if it's any different.

Stuart Greenfield’s picture

It's an interesting point - is the format of the message phone dependent!? I actually have no idea at this stage. However, I am working on the assumption that the MMS structure must be reasonably defined and that the service providers interpret what comes from a phone and parcel it in to an email (I may be completely wrong here...)

The first O2 message contained just an image as an attachment, in a plain text email, with no title.
The next one contained the attachment, but also a title AND a text attachment containing the body.

I am guessing that the phone work flow determines what data goes to the O2 gateway, and the gateway simply assembles a message based on what it receives. If your phone does not provide title or body then nothing comes through.

I have no real way of testing this other than to get more O2 messages via different phones and see what happens :-)

But, based on your test messages we can now tidy up messages of the form attachment + body text in attachment.

The filters are proving pretty easy to write, so if things are more complicated it shouldn't be too hard to adapt them as the sample sizes increase.

At this stage it is more a "Proof of concept" (although concept seems to be being proved at the moment which is great, although clearly a limited sample size!)
________

Just five more minutes...

www.stuartandnicola.com

barrysampson’s picture

We've sent you a new O2 message this time with a title and body text, and a picture of another mug!

coofercat’s picture

I've just sent a picture of my mouse from my Motorola K1 (aka KRAZR), over 02 (contract). It's got a subject of "test post" and says "hello" in the text.

Nice module - I'm looking forward to starting a dodgy "mobile phone pictures" gallery on my site ;-)

Stuart Greenfield’s picture

Thanks for another test - the message has arrived, and the format is the same (image + text attachment). However, the text part has a very different filename to the previous sample message (Txtnnnnnnn.txt versus media2.txt).

Not a problem - I will update the filter and simply take the first text part as the body, rather than matching by filename!

Glad you like how this module is developing - it needs a little more work, but is nearly ready for an official release...

________

Just five more minutes...

www.stuartandnicola.com

coofercat’s picture

I did a few tests, and in every email I saw it had media2.txt - odd... Still, avoiding matching the filename sounds like a good way to avoid this vaguery. I guess we'll find out soon enough if there's a problem with it!

Stuart Greenfield’s picture

Thanks to someone who sent me a picture via the Meteor Ireland network!

Mailsave now sports a Meteor filter :-)
________

Just five more minutes...

www.stuartandnicola.com

barrysampson’s picture

That'll be one of the people I've been hassling :-) Everywhere i go I'm saying, ooh what phone you got?

Stuart Greenfield’s picture

The more phones / networks that send the more comprehensive the set of filters will be!

Thinking about it, there is probably enough here to trigger a new release of mailsave - think it's moved beyond concept stage and is ready for production, but it's quick to add new filters, so keep 'em coming!
________

Just five more minutes...

www.stuartandnicola.com

Mojah’s picture

I asked my brother to send one from South Africa. He confirmed the message was sent on the 17th around 9am London time.

I lost the sony/erricson p800 recently and have never been happier since.

Stuart Greenfield’s picture

I got the message and this is the weirdest format one yet! Looking at the source it looks like a Microsoft Outlook formatted message with lots and LOTS of extra markup.

Do you know what device it was sent from? And whether it was sent as an MMS (in which case all the extras are added by Vodacom) or as email an email (in which case the extras are probably a function of the device's email client)?

I have a filter that processes the message that came through, but this really was an odd one so I'm not sure if it is "standard" or not!

That said, it was only a few minutes to write so I am now thinking that someone with a little bit of PHP skill could probably write their own filter as fast as I can, using the current ones as a template!
________

Just five more minutes...

www.stuartandnicola.com

coofercat’s picture

I know how dev work goes, and lord knows I'm as bad as anyone, but, in the nicest possible way...

I was nearly there with sending you an O2 patch, but couldn't get to the media2.txt attachment, and couldn't work out how I might be able to solve that problem. One problem I had was working out what fields were available in the various data types. If you fancied writing some comments in your favourite filter (or on a web page), or a verbose example or something then it might make things easier (and people like me would send you modules as well as MMS messages ;-)

(sorry, don't want to sound like I'm whinging)

Stuart Greenfield’s picture

I was sure I posted a reply to this earlier today, but it seems to have gone astray... I'll try to remember what I wrote...

Yes - you are right that documentation is currently thin (non-existent?!) for mailsave and its filters, and it's not a whinge to point this out! mailsave is under development at the moment and the modular system it is now adopting started out as something of an experiment. It seems to be working, and the point of making it modular was to make it easier for others to plug-in to it, so some documentation is needed.

I'm currently working away and don't have easy access to the CVS code etc, but I can probably give quick start from memory!

mailsave is called from mailhandler using hook_mailhandler. It intercepts the message and searches out any attachments. It stores these in to an array which is attached to the node as $node->mailsave_attachments[]. Each array entry has keys filename, filepath, filemime and filesize. During processing files are saved with a temporary name (which will appear in the path) while the original name is stored in filename.

Mailsave then calls hook_mailsave_clean to allow a cleanup filter (like the MMS filters) to modify the node content. When the function is called it receives the full node as prepared by mailhandler/mailsave, and it receives all the data about the mailbox that mailhandler supplied.

After hook_mailsave_clean we call hook_mailsave. Modules can intercept this hook to do clever stuff, like converting the node to an image if it finds a jpeg, creating an audio node if it finds an mp3, and so on. hook_mailsave functions can choose to save the node themselves (by returning nothing which indicates the node is complete), or by returning a modified node (which means there is more to do).

When control returns to mailsave any attachments that still exist are attached to the node as a file. Therefore you can prevent a file from being attached by unsetting it.

SO, how does a cleanup filter work...

Looking at the O2 filter as that is the one you mentioned...

First we scan the header string to determine if the message was from O2, by looking at the string after the @. If we find a match then we have an O2 message.

Next, we assign a title if the node didn't already get one from the email message.

Next, we have to look for the first text/plain attachment. Based on the test messages so far O2 sends the message content as a text file (other providers generated format HTML messages). The test messages have had filenames of the format Txtnnnnn.txt and media2.txt. For now the filter looks for the first text/plain message and assumes that is the body (maybe right, maybe wrong - needs more tests!)

So we scan through the $node->mailsave_attachments array until we find text/plain, and then we read the file in and make it the body.

We don't want to attach the file as well, so we unset it from the array so mailsave no longer knows about it.

Job done!

If you know the name of the file you want to discard a filter can call mailsave_discard_attachment($node, $filename). For example, vodafone adds vodafone.gif to its messages, so the vodafone filter can throw it away.

Now, I just checked cvs.drupal.org and for mailsave it is showing mailsave_clean_o2_uk in the main mailsave directory. I re-organised things a little and the filters now live under a sub-directory mms, with names mms_xx_yyyyyyy where xx is a two character country code, and yyyyyyyy is the provider name. So the o2 filter is now mms_uk_o2.module. I'm hoping that when you do a CVS download from HEAD you get the right versions!

So, bit a brain dump - I do need to start documenting this module properly as the whole aim of the re-write was to allow others to take advantage of mailsave as a pure 'extraction' mechanism and to be able to bolt on all sorts of clever extras. (I also need to document flashnode!)

Hope this helps.

Patches very welcome! Mailsave started as a pet project about twelve months ago and it's nice to discover that others want to use it, but also contribute towards its development!

Cheers!!

Stuart
________

Just five more minutes...

www.stuartandnicola.com

Mojah’s picture

He said that he sent it as a standard mms message.

Yup a template filter and asking people to write their own filters will be the best solution seeing that their are so many networks, each with their own formats. In South Africa there are around 4 providers. Here in Argentina we have about 4 also.

Good luck!

Love, Live, Laugh

Stuart Greenfield’s picture

Ok! If that's how a vodacom message looks then that is how it looks! I will leave the filter as is for now.

I think the module is nearing the stage where it can be officially released with the current set of filters. I will see if I can finish it off over the weekend!

I will also leave this thread open for more messages (someone has sent me a picture of their cat - will work on that filter at the weekend too!!)
________

Just five more minutes...

www.stuartandnicola.com

Stuart Greenfield’s picture

Someone sent me a picture of their cat from Cingular. The message doesn't have a title or any body text. Is that because there was no body/title, or because Cingular strips that out?

If the original sender (or someone else on that network) reads this can they send another MMS, being sure to include some text and a title (if their phone allows!)

As it stands this message won't process through mailhandler because it ignores messages that have no body in them, so in this instance mailsave never gets called. (This is a problem with mailhandler, not mailsave)
________

Just five more minutes...

www.stuartandnicola.com

DarkRestraint’s picture

I have no idea if you even check this or if you've closed the email address, but I thought I'd try to help out, since I'm liking where this is going and would be a great help to all drupalista. I'm on the t-mobile network and my phone was a samsung sgh-t539. If you give the go ahead I'll even send another one from my incoming G1 next week.

Thanks!