解析 MIME 消息

发布于 2024-07-24 23:51:19 字数 3509 浏览 4 评论 0原文

对于我的新项目,它有电子邮件模块。我需要在网络上显示所有电子邮件信息。当我调用服务器时,我会获取 Base64 编码的 mime 数据。 应用base64解码技术后,我得到的mime数据如下:

/*********************Mime data start ************ **********************/

From [email protected] Tue Jun 23 12:01:02 2009
Date: Tue, 23 Jun 2009 12:01:02 +0530
From: Prashant R Naik <[email protected]>
To: [email protected]
Subject: This is a test mail
Message-ID: <[email protected]>
Reply-To: Prashant R Naik <[email protected]>
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 数据结束 * **********************************/

现在的问题是我必须解析这些数据并在我的application.由于此数据不是 xml,因此很难解析它(因为使用某些标记解析很容易)。因此任何知道如何解析 mime 数据的人都可以帮助 be.im 使用 erlang 解析此数据。

先感谢您

For my new project which has email module.i need to show all the email information on web.when i m making a call to server i m getting the base64 encoded mime data. after applying base64 decoding technique i m getting the mime data as follows:

/*********************Mime data start ***********************************/

From [email protected] Tue Jun 23 12:01:02 2009
Date: Tue, 23 Jun 2009 12:01:02 +0530
From: Prashant R Naik <[email protected]>
To: [email protected]
Subject: This is a test mail
Message-ID: <[email protected]>
Reply-To: Prashant R Naik <[email protected]>
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 data end ***********************************/

now the problem is i have to parse this data and use it in my application.since this data is not a xml so it difficult to parse it (because parsing with some tag is easy).so any one who knows how to parse mime data help be.i m using erlang to parse this data.

Thank you in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痞味浪人 2024-07-31 23:51:19

gen_smtperlang_smtp 包含解析 mime 消息的代码。

gen_smtp and erlang_smtp contain code for parsing mime messages.

給妳壹絲溫柔 2024-07-31 23:51:19

啊,抱歉……好吧。 然后,本着咕噜和谜语游戏的精神,我只能提供“要么雅司,要么什么都没有”,这不太公平,因为这实际上是两种猜测合二为一。

http://yaws.hyber.org/yapp_intro.yaws

但是,滚动你自己的 mime 解析器不是很难。 获取“边界”并将消息拆分为与“--”匹配的行。 然后对于每个块,解析标题,直到到达 CRLF、CRLF。 然后你的内容就开始了。

我知道“使用不同语言”的回复通常没有帮助。 我猜你没有选择 Erlang 作为“让这项工作变得更容易的语言”,所以我猜有一个外部限制。 您愿意分享一下 Erlang 是您首选解决方案语言的原因吗? :)

Ah, sorry... OK. Then in the spirit of Gollum and the riddle game, I can offer only "Yaws or nothing" which isn't very fair, because it's really two guesses in one.

http://yaws.hyber.org/yapp_intro.yaws

However, rolling your own mime parser isn't very hard. Get the "Boundary" and split the message on lines matching "--". Then for each chunks, parse headings until you get to CRLF, CRLF. Then your content starts.

I know that responses that say "use a different language" are generally unhelpful. I'm going to guess that you didn't chosen Erlang as "the language which will make this job easier", so I'm guessing there's an external constraint. Would you care to share the reason that Erlang is your preferred solution language? :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文