Removing periods from mailbox names

Jan 19, '11 07:30:00AM

Contributed by: titaniumtroop

I've been migrating mail messages to a new Mac mail server from a Windows-hosted one.

Unfortunately, mailboxes with a period ('.') in the mailbox name cause the copy command to error out. One user has about 5,000 mailboxes, so individually removing all the periods by hand was problematic.

I wrote the following AppleScript to remove the periods in each mailbox name for all mailboxes under 'On My Mac.'

tell application "Mail"
 set localMailboxes to every mailbox
 repeat with eachMailbox in localMailboxes
  -- code to test for '.' in mailbox name
  set mailboxName to name of eachMailbox
  -- display dialog mailboxName
  set theDots to offset of "." in mailboxName
  if theDots > 0 then
   set AppleScript's text item delimiters to "."
   set theTextItems to text items of mailboxName
   set AppleScript's text item delimiters to {""}
   set newMailboxName to theTextItems as string
   display dialog "Change mailbox name from " & mailboxName & " to " & newMailboxName & "?" buttons {"Yes", "No"} default button 1
   if button returned of result is "Yes" then set name of eachMailbox to newMailboxName
  end if
 end repeat
end tell

[crarko adds: I haven't tested this one. The script compiles OK; but I don't have any mailboxes with a period in the name (other then the .mbox extension, of course.]

Comments (0)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20110117154637560