I recently switched to the Mac for my work computer (with Windows XP in parallels… I have some VBA macros that are necessary to do my job. Over time, I expect to replace most of it with AppleScript.)

The other day, I noticed some weird emails in my Sent Items Folder in Entourage. They did not have a sender or a subject. If I opened them up, I could see all the headers and any html tags(if any). under the displayed headers, I could see that it was indeed emails that I was sending, but they were somehow becoming corrupted. Today, I figured out that they were emails being sent with my iPhone using my exchange account. I did a little searching and found out that there is a bug that adds some junk to the email header. Outlook on the PC doesn’t get the bad headers because of the way it connects to the server or it just ignores the bad header (it wouldn’t suprise me if the latter was the case).

Fortunately, it is just a simple added three lines at the top of the email and this should be correctable with a script. Since I am trying to learn AppleScript anyway, I thought I would take my chances. After reading a view discussions and blog posts on the issue with some suggested fixes and scripts, I came across an AppleScript made to correct the problem that I decided to examine. Unfortunately, this script didn’t work at all for me, but from looking at the script, it appeared this was mainly due to how it was attempting to detect the “bad email”. Pretty much every “solution” I found required the user to select one or more messages in Entourage and running a script from the Entourage Script menu. Not a very elegant solution, in my opinion. On top of that, it appears that Entourage does not allow AppleScripts to directly modify the email and save it back anyway. Well, I need better detection, and the ability to link the script to an Entourage Rule (and maybe still maintain the ability to run it from the script menu if I wanted.) So, I did and here you go:

Download:

FixSentFromiPhone_1.2.scpt.zip

Here is how I setup my Rule in Entourage to make it run automatically when new message arrive in my sent items folder:
Execute If all criteria are met
If
Folder Is Sent Items
Specific Header Subject Does not exist
Then
Run AppleScript FixSentFromiPhone.scpt

UPDATE: I found that there is a much easier way to do a portion of the script I wrote and updated it.

UPDATE2: It appears my script needs to be made more flexible in order to handle messages with multiple recipients (at least it didn’t work correctly when I did a “reply to all”). I am thinking about it and may update soon.

UPDATE3: Since I had not gotten around to it yet, a reader modified my script and sent me the changes he made to handle messages that had been sent to multiple destinations. I then took his changes and integrated them into the script. Everything seems to work well for me. The download above has been updated. Thanks!

Tags: , , , , , , ,
6 Responses to “Malformed Email Sent From iPhone in Entourage”
  1. Gail says:

    Ricky, this is wonderful, as I’m suffering from this same issue as well. However, I’m not a scripter. Can you tell me how to implement the script you provided? Do I need to place it in a specific location on my machine so the Entourage rule can find it? Thanks again!!

    • Gail says:

      Oh, never mind. As I was setting up the rule, I saw how I could specify the location of the script. Thanks again!

  2. Jeffrey says:

    Thanks a lot, your applescript works great!

  3. Graham says:

    PERFECT!

    This is just what I needed. THe only single drawback is that the script does not permanantly delete the message, just puts it in the deleted items, but I can certianly live with that!

    I posted a link to this on Experts-Exchange.

    • Ricky says:

      If you would like it to delete the message permanently automatically, then just edit the script and repeat the last command, “delete suspectMessage” again. I purposefully left it in the Deleted Items folder so that in case of an error, you still had the original message available. Good Luck.

  4. Thank you, thank you, thank you, thank you, thank you, thank you!

  5.  
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>