Deleting those pesky RFC-822 in-compatible emails with Ruby
If you have landed on this post from Google you already know what I am talking about, if not read the below intro.
I work for an “Enterprisy” company, so the standard here is using the exchange server and I am on Linux using thunder bird. Every once in a while I get those emails that the exchange server cannot convert to an RFC-822 compatible format and thunder bird chokes on em and even the web mail cannot handle these, the only solution so far has been going to the web mail and selecting the mail and moving it to trash.
Finally I wrote a script to automate the whole thing, it telnets into the server checks each message to see if it is RFC-822 compatible and if not moves it into Deleted Items, you can find the script here. (It’s on GitHub feel free to fork it)
Usage ruby telnet-imap.rb <server> <username> <password> <dryrun>
All arguments are self explanatory, dry run can be y/n
PS : if you mange you blow up your inbox you are on your own!!
I’m trying to run this for a co-worker, but keep getting the following DEBUG messages. Is this normal?
D, [2009-02-24T09:12:03.250000 #2252] DEBUG — : * OK Microsoft Exchange Server 2003 IMAP4rev1 server version 6.5.7638.1 (foo.bar.net) ready.
D, [2009-02-24T09:12:03.250000 #2252] DEBUG — : ? BAD Protocol Error: “Unexpected additional characters at the end of command”.
D, [2009-02-24T09:12:03.250000 #2252] DEBUG — : examining folder INBOX
D, [2009-02-24T09:12:03.250000 #2252] DEBUG — : ? BAD SELECT command received in invalid state.
Also, FYI – the script appears to continue even if the initial login fails.
Nop that is not normal, I could offer 2 suggestions
1. Try to log in using telnet and see if you can run the commands and if everything works.
2. Put a debug on the command being sent to make sure it is sending the right command.
Sorry can’t offer anymore help unless I was running it against your server myself.
Thanks for trying the script.
Just wanted to drop a Thank You out there. I’ve been frustrated in this same scenario for a few weeks and your script worked like a charm
I’m running the script now on a 5 GB email box with 37K emails. I’m currently in dryrun mode. Is there a way that the script can grab only the headers as opposed to the full email? It’s printing a lot of unnecessary information to the cmd screen. And will likely take many hours to complete.
@pizza party:
Change the logger output to
@log = Logger.new(‘log.txt’); @log.level = Logger::DEBUG
I’m using
tail -f log.txt | grep INBOX-message
to watch its progress