Mail analysis (source code)

zhaozj2021-02-08  267

Structure of the mail message:

struct ContentHeader {int nType; // = (1) 0 text / plain, = (1) 1 text / html, = (1) 2 maybe attach AnsiString strTransferEncoding; AnsiString strContent; AnsiString strFileName; // for attachment};

Handle the function of each row, processing completely deploy structure ConteHtheader, and save the chain list chlist (TLIST *)

void __fastcall TRecvMailThread :: DealLine (char * line, int len) {int pos; AnsiString strLine (line); AnsiString strTemp (line); strLine = strLine.LowerCase (); switch (nItemKind) {case 0: if (strLine = = "" && Nitems> = 1) // The first portion ends {nitemkind = 1; // enters the next part of Break;} if (((pOS = strline.ansipos ("from:")) == 1) {IF (strfrom == "" "{strfrom = startemp.substring (POS 5, LEN - POS - 4); if (strfrom [1] == 0x20) strfrom = strfrom.substring (2, strfrom.length () - 1); NITEMS ;}} else if ((pOS = strline.ansipos ("to:")) == 1) {if (strto == ") {strto = startemp.substring (POS 3, LEN - POS - 2); if (strTo [1] == 0x20) STRTO = STRTO.SUBSTRING (2, start.length () - 1); NITEMS ; }} Else if ((pOS = strline.ansipos ("Subject:")) == 1) {if (strsubject == "") {strsubject = strTemp.substring (POS 8, LEN - POS - 7); if (strsubject [1] == 0x20) strsubject = strsubject.substring (2, strsubject.length () - 1); NITEMS ;}} else if ((pOS = strline.ansipos ("content-type: multipart") )! = 0) {IF (((pOS =

Strline.ansipos ("Boundary ="))! = 0) {StrnormalBoundary = Strtemp.substring (POS 9, LEN - POS - 8); if (StrnormalBoundary [1] == '/ ") strnormalboundary = strnorboundary.substring (2, Strnormalboundary.Length () - 2); bboundary = true;}} else} ((pOS = strline.ansipos ("boundary ="))! = 0) {strnorboundary = startemp.substring (POS 9, LEN - POS - 8); IF (StrnormalBoundary [1] == '/ ") StrnormalBoundary = StrnormalBoundary.substring (2, strnormAlboundary.length () - 2); bboundary = true;} else f ((pOS = strline.ansipos) ("Content-Type: Text / Plain")))! = 0) {nTextkind = 0; PCH-> NTYPE = 0;} else IF ((POS = Strline.ansipos ("Content-Type: Text / Html"))) ! = 0) {nTextkind = 1; PCH-> NTYPE = 1;} elseiff ((PO S = strline.ansipos ("Content-Transfer-Encoding:")))! = 0) {StrtempenCode = Strline.Substring (POS 27, LEN - POS - 26); PCH-> strartransferencoding = strTempenCode;} Break; Case 1 : If (bboundary) {if (strTemp.ansipos (StrnormalBoundary)! = 0) {file: // Find boundary, nitemkind = 2; Nitems = 0; bboundary = false;}} else {file: // No boundary,

The following is the text part of the message, to "." End PCH-> strcontent = strTemp; Nitemkind = 111;} Break; Case 111: IF (Strline! = ") {PCH-> strcontent = strTemp; PCH-> strContent = "/ r / n";} else {chlist-> add (pch); nitemkind = all_ready;} Break; casp 2: file: // This search for Content-Type, Content-Transfer-Encoding, Boundary, Content -Disposition, etc. // ......... f (strline == "&& nitems> = 1) {file: // enters Next Nitemkind = 3; NItems = 0; Break;} = Strline.ansipos ("Content-Type:")))! = 0) {Nitems ; IF (Strline.ansipos ("Multipart /")! = 0) {IF (((pOS = Strline.ansipos ("Boundary = "))! = 0) {strexpandboundary = strTemp.substring (POS 9, LEN - POS - 8); if (streypandboundary [1] == '/" ') StrExpandBoundary = strExpandBoundary.SubString (2, strExpandBoundary.Length () - 2);! BBoundary = true;} nItemKind = 222; break;} if (strLine.AnsiPos ( "text / plain") = 0) nTextKind = 0 Else IF (Strline.ansipos ("text / html")! = 0) ntextkind = 1; else ntextkind = 2; PCH-> ntype = nTextkind;

Else IF ("Content-Transfer-Encoding:")))! = 0) {NITEMS ; PCH-> strartransferencoding = strline.substring (POS 27, LEN - POS - 26); Else IF ("Content-Disposition:")! = 0) {IF ((POS = Strline.ansipos ("FileName = /"))! = 0) {NITEMS ; PCH-> StrfileName = Strtemp.Substring (POS 10, LEN - POS - 10); Battach = true;}} else} (("filename = /"))! = 0) {NItems ; PCH -> StrfileName = strTemp.substring (POS 10, LEN - POS - 10); Battach = true;} BREAK; Case 3: file: // Receive content to PCH-> strcontent if (strTemp == ") { Chlist-> add (pch); nitemkind = all_ready; break;} if (strtemp.ansipos (strnormAlboundary)! = 0) {chlist- > Add (pch); if (strTemP.ansipos (StrnormalBoundary "-") == 0) // Not until the last {nitemkind = 2; PCH = New ContentHead;} ​​else {nitemkind = all_ready; break;}} else {PCH-> strcontent = strTemp; PCH-> strcontent = "/ r / n";} Break

Case 222: file: // Microsoft Outlook Express if (bboundary) {nitemkind = 333;} else if ((pOS = Strline.ansipos ("Boundary ="))! = 0) {strexpandboundary = strTemp.substring (POS 9 , LEN - POS - 8); IF (streypandboundary [1] == '/ "') strexpandBoundary = strength (2); NITEMKIND = 333;} Break; Case 333: IF (POS = strtemp.ansipos (strexpandboundary))! = 0) {nitemkind = 444; Nitems = 0;} Break; Case 444: file: // This looks up Content-Type, Content-Transfer-Encoding, Boundary, Content-CONTENT- Disposition, etc. // ......... IF (strline == "&& nitems> = 1) {file: // enters Next Nitemkind = 555; NITEMS = 0; Break;}}} ((POS = Strline.ansipos ("Content-Type:")))! = 0) {NITEMS ; Strline = strline.substring (POS 13, LEN - POS - 12); if (Strline.ansipos ("Text / Plain")! = 0) Ntextkind = 10; Else IF (Strline.ansipos ("Text / HTML") ! = 0) nTextkind = 11; else ntextkind = 12; PCH-> NTYPE = NTEXTKIND; Else IF (("Content-Transfer-Encoding:"))! = 0) {NITEMS ; PCH-> strartransferencoding = strline.substring (POS

27, LEN - POS - 26); Else IF (Strline.ansipos ("Content-Disposition:")! = 0) {IF ((POS = Strline.ansipos ("filename = /"))! = 0) {Nitems ; PCH-> strfilename = strTemp.substring (POS 10, LEN - POS - 10);}} else f ((pOS = strline.ansipos ("filename = /"))! = 0) { NItems ; pch-> strfilename = strTemp.substring (POS 10, LEN - POS - 10);} Break; Case 555: file: // Receive content to PCH-> strcontent if (strTemp == ".") {CHList-> Add (pCH); nItemKind = ALL_READY; break;} if (! strTemp.AnsiPos (strExpandBoundary) = 0) {CHList-> Add (pCH); pCH = new ContentHeader; if (strTemp.AnsiPos (strExpandBoundary "-") == 0) // Not until the last {nitemkind = 444; NITEMS = 0;} else {Nitemkind = 1; bboundary = true; break;}} else {pch-> strcontent = strTemp; PCH-> strcontent = "/ r / n";} Break;}} will be charged by mail Original Branch Processing

Mail is TMEMORYSTREAM *, which is stored in the original text.

转载请注明原文地址:https://www.9cbs.com/read-1759.html

New Post(0)