daily pastebin goal

Applescript to fix emails with hidden attachments

a guest Jan 30th, 2013 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set newFileName to (path to temporary items folder from user domain as string) ¬
  2.         & (random number from 10000 to 99999) ¬
  3.         & ".eml"
  4. tell application "Mail"
  5.         set selectedMails to the selection
  6.         if the length of selectedMails is greater than 0 then
  7.                 repeat with theMessage in selectedMails
  8.                         set newSource to my replaceText("Content-Type: multipart/related;", "Content-Type: multipart/mixed;", source of theMessage)
  9.                         set newFile to open for access newFileName with write permission
  10.                         write newSource to newFile starting at 0
  11.                         close access newFile
  12.                         open newFileName
  13.                 end repeat
  14.                 tell application "Finder" to delete file newFileName
  15.         else
  16.                 display alert "Selezionare uno o più messaggi e riprovare"
  17.         end if
  18. end tell
  20. on replaceText(find, replace, someText)
  21.         set prevTIDs to text item delimiters of AppleScript
  22.         set text item delimiters of AppleScript to find
  23.         set someText to text items of someText
  24.         set text item delimiters of AppleScript to replace
  25.         set someText to "" & someText
  26.         set text item delimiters of AppleScript to prevTIDs
  27.         return someText
  28. end replaceText
RAW Paste Data