我目前正在 golang 中使用 net/mail
解析電子郵件。
import ( "net/mail" "io" "strings" ) func main() { email := "some email received" reader := strings.newreader(emailinput) msg, err := mail.readmessage(inputreader) check(err) body, err := io.readall(msg.body) check(err) fmt.println(string(body)) }
這對於純文字電子郵件來說效果很好。但是,當我使用包含 html 的 apple mail 應用程式發送電子郵件時,返回了以下正文:
--Apple-Mail=3D_4A1E75FB-9514-439D-B922-8526851CA743 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=3Dus-ascii fn main() { println!("Hello world!"); } --Apple-Mail=3D_4A1E75FB-9514-439D-B922-8526851CA743 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=3Dus-ascii <html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; charset= =3Dus-ascii"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode= : space; line-break: after-white-space;" class=3D""><pre class=3D"" style= =3D"color: rgb(209, 209, 209); background-color: rgb(0, 0, 0);">fn <span cl= ass=3D"" style=3D"color: rgb(230, 97, 112); font-weight: bold;">main</span>= <span class=3D"" style=3D"color: rgb(210, 205, 134);">(</span><span class= =3D"" style=3D"color: rgb(210, 205, 134);">)</span> <span class=3D"" style= =3D"color: rgb(176, 96, 176);">{</span> println<span class=3D"" style=3D"color: rgb(210, 205, 134);">!</span><spa= n class=3D"" style=3D"color: rgb(210, 205, 134);">(</span><span class=3D"" = style=3D"color: rgb(2, 208, 69);">"</span><span class=3D"" style=3D"color: = rgb(0, 196, 196);">Hello world!</span><span class=3D"" style=3D"color: rgb(= 2, 208, 69);">"</span><span class=3D"" style=3D"color: rgb(210, 205, 134);"= >)</span><span class=3D"" style=3D"color: rgb(176, 96, 176);">;</span> <span class=3D"" style=3D"color: rgb(176, 96, 176);">}</span>
以上是使用 net/mail 解析電子郵件的詳細內容。更多資訊請關注PHP中文網其他相關文章!

goisastrongchoiceforprojectsneedingsimplicity,績效和引發性,butitmaylackinadvancedfeatures and ecosystemmaturity.1)

Go'sinitfunctionandJava'sstaticinitializersbothservetosetupenvironmentsbeforethemainfunction,buttheydifferinexecutionandcontrol.Go'sinitissimpleandautomatic,suitableforbasicsetupsbutcanleadtocomplexityifoverused.Java'sstaticinitializersoffermorecontr

thecommonusecasesfortheinitfunctionoare:1)加載configurationfilesbeforeThemainProgramStarts,2)初始化的globalvariables和3)runningpre-checkSorvalidationsbeforEtheprofforeTheProgrecce.TheInitFunctionIsautefunctionIsautomentycalomationalmatomatimationalycalmatemationalcalledbebeforethemainfuniinfuninfuntuntion

ChannelsarecrucialingoforenablingsafeandefficityCommunicationBetnewengoroutines.theyfacilitateSynChronizationAndManageGoroutIneLifeCycle,EssentialforConcurrentProgramming.ChannelSallSallSallSallSallowSallowsAllowsEnderDendingAndReceivingValues,ActassignalsignalsforsynChronization,and actassignalsynChronization and andsupppor

在Go中,可以通過errors.Wrap和errors.Unwrap方法來包裝錯誤並添加上下文。 1)使用errors包的新功能,可以在錯誤傳播過程中添加上下文信息。 2)通過fmt.Errorf和%w包裝錯誤,幫助定位問題。 3)自定義錯誤類型可以創建更具語義化的錯誤,增強錯誤處理的表達能力。

Gooffersrobustfeaturesforsecurecoding,butdevelopersmustimplementsecuritybestpracticeseffectively.1)UseGo'scryptopackageforsecuredatahandling.2)Manageconcurrencywithsynchronizationprimitivestopreventraceconditions.3)SanitizeexternalinputstoavoidSQLinj

Go的錯誤接口定義為typeerrorinterface{Error()string},允許任何實現Error()方法的類型被視為錯誤。使用步驟如下:1.基本檢查和記錄錯誤,例如iferr!=nil{log.Printf("Anerroroccurred:%v",err)return}。 2.創建自定義錯誤類型以提供更多信息,如typeMyErrorstruct{MsgstringDetailstring}。 3.使用錯誤包裝(自Go1.13起)來添加上下文而不丟失原始錯誤信息,

對效率的Handleerrorsinconcurrentgopragrs,UsechannelstocommunicateErrors,enplionErrorWatchers,Instertimeout,UsebufferedChannels和Provideclearrormessages.1)USEchannelelStopassErtopassErrorsErtopassErrorsErrorsErrorsFromGoroutInestOthemainFunction.2)


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SublimeText3 Linux新版
SublimeText3 Linux最新版

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。