我需要能够将电子邮件附加到模型,特别是 .eml 和 .msg 文件
Paperclip 现在需要验证使用它上传的文件类型。
这些验证所在的代码部分在这里:
validates_attachment_content_type :supporting_document,
:content_type => ['application/pdf', 'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'image/jpeg', 'image/jpg', 'image/png',
'application/vnd.ms-excel.sheet.macroEnabled.12', 'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',EML_MIMETYPE],
:message => 'incorrect file type.'
最后一部分 EML_MIMETYPE 用于 .eml 文件,并定义为常量:
EML_MIMETYPE = 'message/rfc822'
通过在测试 .eml 文件的终端中使用 file 命令,我找到了 .eml 文件的正确 MIME TYPE:
$ file -b --mime-type ~/Desktop/noname.eml
但是,当我对示例 .msg 文件执行此操作时,它会返回看起来像是损坏的 MIME 类型的内容
$ file -b --mime-type ~/Desktop/testemail.msg
>application/CDFV2-corrupt
在线查看,此链接http://social.msdn.microsoft.com/Forums/en-US/8efe300d-c917-4be7-a0f3-e620e029842b/what-mime-type-can-i-use-for-msg-files ?forum=netfxnetcom建议使用 MIME 类型的 "application/vnd.ms-outlook" ,但我没有运气。
有什么建议么?我正在运行 linux xubuntu 14.04,该应用程序使用的是 Rails 3.2.18 和 ruby 1.9.3p392