Applescript 将Mail.app中选择的邮件导出为emlx
我想将指定邮箱中选定的电子邮件导出到Finder。我在网上找到了这个脚本,并根据自己的喜好修改了它。但它似乎没有出口。有人知道哪里出了问题吗Applescript 将Mail.app中选择的邮件导出为emlx,applescript,Applescript,我想将指定邮箱中选定的电子邮件导出到Finder。我在网上找到了这个脚本,并根据自己的喜好修改了它。但它似乎没有出口。有人知道哪里出了问题吗 tell application "Mail" set msgs to message of mailbox "test1" of account "Info" if length of msgs is not 0 then display dialog "Export selected message(s)?"
tell application "Mail"
set msgs to message of mailbox "test1" of account "Info"
if length of msgs is not 0 then
display dialog "Export selected message(s)?"
if the button returned of the result is "OK" then
-- set up month parsing value for French Vanilla algorithm
set fixedDate to current date --or any other date
set month of fixedDate to January
-- set theFolder to "Macintosh HD:Users:rajsingh:Desktop:" as alias
set theFolder to choose folder with prompt "Save Exported Messages to..." without invisibles
repeat with msg in msgs
-- get path to message
set mb to mailbox of msg
set mba to account of mb
-- mtype is returning 'constant **** ETIM' when it should be imap (for OGC account)
-- set mtype to (account type) of mba
set mtype to "imap"
set accountpath to account directory of account of mb
set fullpath to accountpath & name of mb & "." & mtype & "mbox:Messages:"
-- figure out message name
set msgfilename to id of msg
set atts to number of mail attachments of msg
if atts > 0 then
set msgfilename to msgfilename & ".partial.emlx"
else
set msgfilename to msgfilename & ".emlx"
end if
set fullpath to fullpath & msgfilename
set theFile to fullpath as rich text
-- create new name prefix based on date
set msgDate to date received of msg
-- parse date
-- use French Vanilla algorithm to get month number
set theMonth to (2 + (msgDate - fixedDate + 1314864) div 2629728) as rich text
if length of theMonth < 2 then
set theMonth to "0" & theMonth
end if
set theDay to day of msgDate as rich text
if length of theDay < 2 then
set theDay to "0" & theDay
end if
set msgDate to (year of msgDate as rich text) & theMonth & theDay & "at" & hours of msgDate & minutes of msgDate & seconds of msgDate
set comparison_string to ":/"
set replacement_string to "->"
set msgSubject to ""
set msgSubject to my replaceText("Re- ", "", msgSubject)
set msgSubject to my replaceText("Re-", "", msgSubject)
--set msgSubject to text 1 thru 49 of msgSubject
set newFile to msgSubject & "_" & msgDate & ".emlx" as rich text
--set newFile to (msgSubject & "_" & msgDate & "_" & msgfilename) as text
-- copy mail message to the folder and prepend date-time to file name
tell application "Finder"
try
set intFile to ""
duplicate file theFile to folder theFolder
on error
display dialog theFile & theFolder
display dialog "couldn't duplicate " & intFile
end try
-- rename file
try
set name of intFile to newFile
on error
display dialog "couldn't set name of " & intFile & " to " & newFile
end try
-- reveal intFile
-- open theFile as alias
end tell
end repeat
beep 2
display dialog "Done exporting " & length of msgs & " messages."
end if -- OK to export msgs
end if -- msgs > 0
end tell
on replaceText(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
set text item delimiters of AppleScript to replace
set subject to "" & subject
set text item delimiters of AppleScript to prevTIDs
return subject
end replaceText
告诉应用程序“邮件”
将msgs设置为帐户“Info”的邮箱“test1”的邮件
如果MSG的长度不是0,则
显示“导出所选邮件”对话框
如果返回结果的按钮为“OK”,则
--为French Vanilla算法设置月份解析值
将fixedDate设置为当前日期--或任何其他日期
将固定日期的月份设置为1月
--将文件夹设置为“Macintosh HD:Users:rajsingh:Desktop:”作为别名
设置文件夹以选择文件夹,并提示“将导出的邮件保存到…”而不显示
用msgs中的msg重复
--获取消息的路径
将mb设置为msg的邮箱
将mba设置为mb帐户
--mtype在应为imap时返回“常量****ETIM”(对于OGC帐户)
--将mtype设置为mba的(帐户类型)
将mtype设置为“imap”
将accountpath设置为mb帐户的帐户目录
将完整路径设置为accountpath&mb&“&mtype&“mbox:消息的名称:”
--找出消息名
将msgfilename设置为msg的id
将atts设置为msg的邮件附件数
如果atts>0,则
将msgfilename设置为msgfilename&“.partial.emlx”
其他的
将msgfilename设置为msgfilename&“.emlx”
如果结束
将fullpath设置为fullpath&msgfilename
将文件设置为富文本格式的完整路径
--基于日期创建新的名称前缀
将msgDate设置为收到消息的日期
--解析日期
--使用法语香草算法获取月数
将month设置为(2+(msgDate-fixedDate+1314864)div 2629728作为富文本
如果月长小于2,则
将每月设置为“0”&每月
如果结束
将msgDate的日期设置为富文本
若一天的长度小于2,则
将日期设置为“0”&日期
如果结束
将msgDate设置为(以富文本形式显示msgDate的年份)&msgDate的月份、日期、时间、分钟和秒
将比较字符串设置为“:/”
将替换字符串设置为“->”
将msgSubject设置为“”
将msgSubject设置为my replaceText(“Re-”,“”,msgSubject)
将msgSubject设置为my replaceText(“Re-”,“”,msgSubject)
--将msgSubject设置为msgSubject的文本1到49
将newFile设置为msgSubject&“”&msgDate&“.emlx”作为富文本
--将newFile设置为文本形式(msgSubject&“”&msgDate&“”&msgfilename)
--将邮件复制到文件夹,并将日期时间前置到文件名
告诉应用程序“查找器”
尝试
将intFile设置为“”
将文件复制到文件夹文件夹文件夹
论错误
显示文件文件夹对话框(&F)
显示对话框“无法复制”&intFile
结束尝试
--重命名文件
尝试
将intFile的名称设置为newFile
论错误
显示对话框“无法将“&intFile&”的名称设置为“&newFile”
结束尝试
--显示内部文件
--将文件作为别名打开
结束语
结束重复
嘟嘟声2
显示对话框“完成导出”&MSG的长度和“消息”
如果结束--OK以导出MSG
如果--msgs>0,则结束
结束语
关于替换文本(查找、替换、主题)
将prevTIDs设置为AppleScript的文本项分隔符
设置要查找的AppleScript的文本项分隔符
将主题设置为主题的文本项
设置要替换的AppleScript的文本项分隔符
将subject设置为“”&主题
将AppleScript的文本项分隔符设置为prevTIDs
返回主题
结束替换文本
消息路径如10.8中所示:
~/Library/Mail/V2/IMAP-example@imap.gmail.com/[Gmail].mbox/Trash.mbox/C523787F-3D53-4A6E-BA48-516ACC5B68DD/Data/2/Messages/2496.emlx
您可以按邮件ID搜索邮件:
tell application "Mail"
selected messages of message viewer 1
repeat with m in result
do shell script "find ~/Library/Mail/V2 -name " & (get id of m) & ".\\* -exec cp {} ~/Desktop \\;"
end repeat
end tell
你下面的脚本工作得很好,我想把它包括在规则中,但我完全是新手 脚本编写 谢谢你的回答
__________________________________
告诉应用程序“邮件”消息查看器1的选定消息
在结果中用m重复
执行shell脚本“find~/Library/Mail/V2-name”&(获取m的id)&“\*-exec cp{}~/Desktop/”&引用我的replace(m的主题“/”,“)&.emlx\;”
结束重复
结束讲述
替换时(输入,x,y)
将文本项分隔符设置为x
将t设置为输入的文本项
将文本项分隔符设置为y
t作为文本
端部更换
________________________________
可能重复的
________________________________