对于我的新项目,它有电子邮件模块。我需要在网上显示所有的电子邮件信息。当我打电话给服务器时,我得到了base64编码的mime数据。在应用base64解码技术后,我得到如下的mime数据:
/ ********************* Mime数据启动********************** ************* /
From prashant.n@geodesic.com Tue Jun 23 12:01:02 2009
Date: Tue, 23 Jun 2009 12:01:02 +0530
From: Prashant R Naik <prashant.n@geodesic.com>
To: koushik.narayanan@geodesic.com
Subject: This is a test mail
Message-ID: <20090623063102.GA27080@picopeta.com>
Reply-To: Prashant R Naik <prashant.n@geodesic.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="ReaqsoxgOBHFXBhH"
Content-Disposition: inline
User-Agent: Mutt/1.5.18 (2008-05-17)
Status: RO
Content-Length: 1912
Lines: 52
--ReaqsoxgOBHFXBhH
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Test mail.
Initiated by prashant
Regards,
--
Prashant R Naik
Principal Technologist | Symbian & Web2.0
Geodesic Limited | www.geodesic.com
Tel: +91-80-66551000
--ReaqsoxgOBHFXBhH
Content-Type: image/gif
Content-Disposition: attachment; filename="trash.gif"
Content-Transfer-Encoding: base64
R0lGODlhEAAQANUoADJ8wTqU2DmR1TqV2DN9wTSBxTWFyTaGyTJ9wTWGyTaKzjmS1TOAxTuV
2DaFyTN8wDiN0jiO0jSAxTeKzjqS1DN8wTqR1TWFyjB4vTOBxTmO0TmS1DaKzTeJzTqV1zSA
xDJ8wDqS1TeKzTF4vDF4vTiO0f///zuX2gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAACgALAAA
AAAQABAAAAaDQNRpSCwWhcakcsk8mZ5Qpik5pUKvT2W1uDVWp+BiYNAImAZmz/lcDoQEFoFp
QTFtTPKFQLCAREolJiURJhCCJhqAJRMiIhwmjSYdJgqUjQoODgkJJgecBp0mBgYXBx8ZBQxY
UAUSDAUACLEPDwgEAAAEIBUEtygkIyMkwMMYw8EjKEEAOw==
--ReaqsoxgOBHFXBhH
Content-Type: image/jpeg
Content-Disposition: attachment; filename="bx.jpg"
Content-Transfer-Encoding: base64
/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAAR
CAAUAAoDAREAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAn/xAAYEAEAAwEAAAAAAAAA
AAAAAAAAGWen5//EABQBAQAAAAAAAAAAAAAAAAAAAAD/xAAUEQEAAAAAAAAAAAAAAAAAAAAA
/9oADAMBAAIRAxEAPwCb4AJHym0Vp3PQJTaK07noJHgA/9k=
--ReaqsoxgOBHFXBhH
Content-Type: image/png
Content-Disposition: attachment; filename="day_bg.png"
Content-Transfer-Encoding: base64
iVBORw0KGgoAAAANSUhEUgAAAGQAAAApCAYAAADDJIzmAAAABmJLR0QA/wD/AP+gvaeTAAAA
CXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH2AwCCS0kTriU2QAAAB10RVh0Q29tbWVudABD
cmVhdGVkIHdpdGggVGhlIEdJTVDvZCVuAAAAXElEQVR42u3bQQEAMAgDMZiqiZtP5AwbfeQk
NO/WvPtLMR0TABEQIAICRECACAgQAREQIAICRECACAgQAREQIAICRECACAgQAREQIAICRECA
CAgQARGQ7NpPPasFT+0FZPjBRwYAAAAASUVORK5CYII=
--ReaqsoxgOBHFXBhH--
/ ********************* Mime数据结束********************** ************* /
现在问题是我必须解析这些数据并在我的应用程序中使用它。因为这个数据不是一个xml所以很难解析它(因为解析一些标签很容易)。所以任何一个谁知道如何解析mime数据帮助be.im使用erlang来解析这些数据。
提前谢谢
答案 0 :(得分:4)
gen_smtp和erlang_smtp包含用于解析mime消息的代码。
答案 1 :(得分:2)
啊,对不起......好的。然后在咕噜咕噜的精神和谜语游戏中,我只能提供“雅司病”或“没有”,这不是很公平,因为它实际上只有两个猜测。
http://yaws.hyber.org/yapp_intro.yaws
但是,滚动自己的mime解析器并不是很难。获取“边界”并将消息拆分为匹配“ - ”的行。然后对于每个块,解析标题,直到你到达CRLF,CRLF。然后你的内容就开始了。
我知道说“使用不同语言”的回答通常是无益的。我猜你没有选择Erlang作为“使这项工作更轻松的语言”,所以我猜测有一个外部约束。您是否愿意分享Erlang是您首选的解决方案语言的原因? :)