O2, Email and Flickr (Or how I learned not to worry about big companies and devise my own workarounds)*
Sunday, July 24th, 2005Ok let me start of with a little story. Once upon a time Andy brought a really nice phone, it had a great little camera and was capable of sending MMS, SMS and even emails. Andy was really happy with his phone, he even went to go see Green Day, took some photos and then posted them straight to flickr via email! Andy was the talk of the town, he was super cool, totally fab and now with his new toy, a touch bit sexier.
But then out of the blue 02 changed something which made Andy a very unhappy bunny. 02 in their wisdom had decided to change the way photos were sent by email from a phone. Now instead of attaching the photo file (a happy little .Jpeg) to a fairly blank email, they in its place sent an email in HTML format with no attachments.
Why was (is) Andy so upset with this? Well doing this upset(s) Andy for a few reasons
When Andy found out about this he was very upset. He cried for a little bit, found somebody to hug, cried a little more but then he decided to write an email to the nasty O2 people that had brought him so much anguish. The email Andy sent basically stated the problems above, pushing the issues of possible breaches in privacy and the fact that he is not actually sending a photo by email. This was Friday, Andy wasn’t expecting anything to be done till next week sometime, so you would think he would have to wait to see the result. Oh, then you don’t know Andy. With a pack of Jaffa cakes, beer, tea and Diet Pepsi, Andy took on 02’s crappy new email in an attempt to make a work around.
Ok, I am going to change and start speaking in the first person to explain what is going on. I am attempting on my webserver to set up an email account which effectively receives this new shitty O2 email, strips it down, rips out the information, finds and downloads the full sized image from 02’s site and then email it on to flickr. No small feat. I have however found out how O2’s end work, and if you interested in code and how this works, please read on, if not, I would run away.
First thing I needed was to connect to an email account via pop3 which I would send the email to from my swanky phone. I am going to skip on how to get a script to connect to a pop3 server, and then go through a new email line by line. Although this is complicated, there are some fine examples around. For what it’s worth I just grabbed my trusty wordpress installation and read through the code of wp-mail.php. I then took out all the bits I didn’t need and was left with a script which looks at a pop3 account for a message, if it finds one, it runs through it line by line to make it ready for a post or with a little alteration in our case, an email.
After that we need to get the URL of the full sized photo stored at O2’s crappy site. To get this URL from the new O2’s photo email there are 2 values that you need to extract from the email message source. These two values are the mmsId and encmmsId. The emcmmsId can be found in the URL labelled “View Message� if you so happen to view the vile email. Here are some fun facts about it
http://139.2.165.14/mms2legacy/showMessage2.do?encMmsId=89D9CC251797CD47
Ok that’s the first part. Now we need the mmsId. This took me ages to find, but the mmsId is the file name of the image displayed in the email, but without the .jpg extension. Again here are some facts.
Now with these 2 numbers you can grab the actual full sized photo. O2 store these images in some crazy database, so you can’t get a direct link to it like http://www.o2.com/myacephoto.jpg. Oh no, to get the full sized image of our particular example we would use a URL like this
http://139.2.165.14/mms2legacy/downloadMedia2.d……..
As you might have spotted we have both Id numbers in there, encMmsId and mmsId. In front of those is what I think is a static IP and script which accept these two variables and another called selectedItem. selectedItem refers to the webpage that we were supposed to visit to get the full sized image, it simply refers to which image is selected to download. So if the message sent from our phone contained more than one picture, this would increment by one, I would presume (not tested).
Now that is ace, but how on earth do I get a script to automate downloading this image. Well on a Linux/unix/*nix based box you should have wget installed. If you do and its up to date you can run this command. (slightly phpified)
wget -O /path/to/your/photo/cache/' . $encMmsId . '.jpg --post-data=encMmsId=' . $encMmsId . '&mmsId=' . $mmsId . '&selectedItem=1 http://139.2.165.14/mms2legacy/downloadMedia2.do?
In php you would wrap all of this within the system() command. If you put this in a loop where it checks through each email, you should be able to collect a nice cache of images which you could then email on using commands such as php’s mail() method.
Unfortunately, this is where I stop as I have asked my webhosts to upgrade wget to something which can handle the –post-data flag. However, it should give anybody a head start into this sort of thing. For people using Orange phones, I think you have the same problem but I have yet to investigate it. As for other networks I might get round to you :)
Anyhow, as for now I hope this is of use to somebody. I would actually love it if flickr themselves put it inside their system if O2 don’t see sense and revert back to emailing people their photos. I shouldn’t have to do this, O2 should see google, amazon, flickr and the BBC opening up their API’s to random people, not for short term profit but to encourage people to play around with new technology. I fear O2 have done this to make people think twice about emailing photos, in an effort to push people into MMSing to other phones, something which costs the earth in the UK at least.
*the title might be a slight take on a film