2009-06-25 114 views
2

對於我的新項目有電子郵件module.i需要顯示所有的電子郵件信息在web.when我打電話給服務器我得到base64編碼的MIME數據。在應用base64解碼技術後,即時獲取MIME數據如下:解析MIME郵件

/********************* Mime數據啓動******** ***************************/

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數據結束***********************************/

現在的問題是我必須解析這些數據並將它用在我的應用程序中。因爲這些數據不是xml,所以很難解析它(因爲用一些標籤解析很簡單).so任何知道如何解析MIME數據的人幫助be.im使用erlang來解析這些數據。

預先感謝您

回答

4

gen_smtperlang_smtp包含代碼解析MIME消息。

+0

但似乎沒有用在我的上下文任何方式thanx – Abhimanyu 2009-06-25 11:07:14

2

啊,對不起...好的。然後,根據咕嚕和謎語的精神,我只能提供「非雅」或「不雅」,這是不公平的,因爲它真的是兩個猜測之一。

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

然而,滾動自己的MIME解析器是不是很辛苦。獲取「邊界」並將消息拆分爲匹配「 - 」的行。然後,對於每個塊,解析標題直到您到達CRLF,CRLF。然後你的內容開始。

我知道說「使用不同語言」的回覆通常是無益的。我猜測你沒有選擇Erlang作爲「將使這項工作更容易的語言」,所以我猜測存在外部約束。您是否願意分享Erlang是您首選的解決方案語言的原因? :)