Monday, July 6, 2009

Processing Email with PHP?

That's what I've been doing on and off for a week... writing and refining a script to pull formmail output from a POP3 box and enter them in vTiger. Since vTiger has a SOAP command for adding new leads, I've also been doing that. The script gets all the email bodies, parses them, enters them with SOAP, then updates them with MySQL. (I figure the SOAP will create any records in tables I don't know about; vTiger's database is hella normalized out the ass.)

While working on this I ran into two problems and, between myself and my client, we found solutions.

Firstly, I couldn't connect to a certain mail server -- it was timing out. I was about to launch into hour two of debugging my script when I realized I needed to see with my eyes what the mail server was doing. It was SSL-only access, and I didn't know about this until a few minutes later: "How to telnet to a POP server that requires SSL." Very interesting, and it worked right away, t'boot - at least, for diagnostic purposes. Turned out something was wrong with OpenSSL on the site, and once we had good info for a support ticket, the server staff fixed it.

The other snag was non-standard characters of text killing the SOAP inserts. Some 100+ entries into a batch there was an email causing my script a fatal error, due to an uncaught exception in SoapClient. I found an article by Entrepreneur Geek, "Funny characters, Webservices, and UTF8" which gave me copy-paste-able versions of all the characters he had found to kill Soap over the years. When I pasted them into the code, they were mangled immediately, with little question-mark-diamond-box characters and the code to produce them taking up either two or three cursor positions for a single "actual" character. Well, that's actually a good sign, I guessed, and I wrapped those funky characters into some str_replace() and just ganked them. Then I wrapped the soap insert call in a try() / catch() block and life was good. 15,000+ emails processed in about a day.

And yeah, all this was going on while, simultaneously, the subject of yesterday's blog post was also going on.

Copyright © 2008 theNthDoctor.com. Some content may be the property of third parties; it is used in a fair use context unless otherwise noted. If you are getting this content from any site other than thenthdoctor.blogspot.com or thenthdoctor.com, please notify Nathan Hawks via nhawks (at) gmail (dot) com.

2 comments:

Immi said...

Ok, so I'm behind and just read the commentluv enfuckification thing. Emailed Andy? he's usually good about helping out.
As fpr the PHP doodad, doing something is more distracting than doing anothing at least.
*hugs*

Nathan Hawks said...

Thankfully, at least the new comments are being stored right, but I don't think I've entirely fixed things. And no, haven't emailed Andy yet, I'm a bit bogged down at the moment :/

As for the PHP, well, not only was it distracting, it was paying work. I was kinda dragged through it kicking and screaming, but that's what's good about clients who are also friends.

Somewhere in a deprived part of my mind, there are some neurons celebrating that I can do a good job on a programming job after letting those skills collect dust in the career change.

Your typing skills are suffering darlin'... looks like the med increase is kicking in eh?

A note about comments

Hey readers! I recently used CommentLuv to completely enfuckify all the past comments on this site. Somehow, people were entering comments as me! So I removed the javascript that runs CommentLuv, and then guess what happened? IT REPLACED ALL COMMENT AUTHORS WITH ME! So, unfortunately it's going to look like I'm talking to myself, and everybody's links to their own sites have been lost. It sucks, and worst of all I have to write this huge header explaining :P

Previous Posts, Newest First