(It’s been awhile since I’ve done a technical post, so I may do that on the next few.)
Through some craziness we haven’t figured out, a user at work managed to get over *pinky to mouth* one million items in their Deleted Items folder in Outlook which is hooked up to our Exchange server. This turned into an interesting problem.
Needless to say, that is a stupid amount of items that Outlook had issues with processing.Â Telling Outlook to empty the trash would send it out into la-la land as a hung process. I’m thinking it was trying to pull all million items into memory to do a delete on them. I’m sure if we let it sit long enough it may have done something, but it just really didn’t like that volume of stuff. Â Similarly, using another Exchange or IMAP client like Mail.app, Thunderbird, and mutt had similar issues as they needed to retrieve the million headers before they would do anything. Deleting it batches at a time by hand worked, but was slow and required someone to do it by hand which…we can see the issue there.
As is often the case, the solution to the problem could be had by creating a small script to do the pain in the butt stuff for you. Actually, the big reason a script works here is that it could be smart and just snag small batches and work on those. Luckily, a few months back I had played with Viewpoint, a “rubyÂ client access library for Microsoft Exchange Web Services.Â Previously, I had used Viewpoint to read mail in a certain folder and generate stats for it, so using it to identify and delete messages would be a snap.
The first go around I was grabbing the messages in a batch and deleting them one by one. Â That works, but was a bit slow. Â I figured out how to do something that hasn’t been written into Viewpoint yet: a batch delete. Â That sped up the operation by 4.5 times or so. Â This still took over a day to run. Â It also couldn’t delete everything. Â For some reason it seemed to not be able to delete calendar invites. Â After the script was running entirely, we were left with about 30,000 items left behind, but Outlook could handle wiping the rest of them out if we left it alone for 20 minutes or so.
Continue reading Using Ruby with Viewpoint unhork an Exchange mailbox