Gar*_*son 6 ruby outlook ruby-on-rails paperclip-validation
我需要能够将电子邮件附加到模型,特别是 .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.'
Run Code Online (Sandbox Code Playgroud)
最后一部分 EML_MIMETYPE 用于 .eml 文件,并定义为常量:
EML_MIMETYPE = 'message/rfc822'
我通过在终端中对测试 .eml 文件使用 file 命令找到了 .eml 文件的正确 MIME 类型:
$ file -b --mime-type ~/Desktop/noname.eml
但是,当我对示例 .msg 文件执行此操作时,它会返回看起来像是损坏的 MIME 类型的内容
$ file -b --mime-type ~/Desktop/testemail.msg
>application/CDFV2-corrupt
Run Code Online (Sandbox Code Playgroud)
在线查看,此链接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