TCPIP (Nine)

zhaozj2021-02-17  45

(* @ @ @ @ @ @ @ @ @ @ / C c c * ** (* @ /// Constructor t_news.create (aowner: tcomponent); *) Constructor T_News.create (Aowner: Tcomponent); Begin inherited Create (Aowner); f_nntp: = nil; f_NewsGroups: = TStringList.create; end; (* @ /// 0000000501 *) (* @ /// destructor t_news.destroy; *) deStructor t_news.destroy; begin f_newsgroups.free; inherited destroy; end; (* @ @ @ @ @ @ @ @ @ @ @ @ @ @ 00000030f *)

(* @ /// procedure t_news.SetNewsgroups (Value: TStringList); *) procedure t_news.SetNewsgroups (Value: TStringList); begin if value = NIL then f_newsgroups.clear else f_newsgroups.assign (value); end; (* @ /// 000,0000603 *)

(* @ /// procedure t_news.action; *) procedure t_news.action; var s: string; i: integer; begin if (f_nntp = nil) or (f_newsgroups = nil) OR (f_newsgroups.count = 0) OR F_newsgroups.count> 10) (* no spamming, please *) or (f_from = '') THEN EXIT; S: = 'newsgroups:'; i: = 0; While True Do Begin S: = S F_NewsGroups.Strings [ I]; INC (i); if i = f_newsgroups.count dam; s: = '; END; if f_organization <> '' TENF_MESSAGE.ADD (f_organization); inherited action; f_nntp.login; f_nntp.news :=f_message; f_nntp.postarticle; f_nntp.logout; f_message.clear; end; (* @ /// *) (*) @ @ / @00000401 *)

(* @ /// class t_attachment (TObject) *) (* @ /// constructor t_attachment.Create; *) constructor t_attachment.Create; begin inherited create; f_text: = TStringlist.create; f_data: = TMemoryStream.Create; f_encoding : = EC_NONE; END; (* @ /// 0000000617 *) (* @ /// deStructor t_attachment.destroy; *) deStructor t_attachment.destroy; recomgin f_text.free; f_data.free; inherited destroy; end; (* @ /// *) (* @ /// procedure t_attachment.SetText (value: TStringList); *) procedure t_attachment.SetText (value: TStringList); begin if value = NIL then f_text.clear else begin f_text.assign (value) ; f_text.SaveToStream (TMemoryStream (f_data)); end; end; (* @ /// 0000000701 *) (* @ /// procedure t_attachment.SetData (value: TStream); *) procedure t_attachment.SetData (value: TStream Begin if value = nil damorystream (f_data). Clear else begin f_text.clear; tmemorystream (f_data) .loadFromstream (value); end; end; (* @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ / / * ) (* @ /// class t_mime (tcomponent) *) (* @ /// constructor t_mime.create (Aowner: Tcom PONENT); *) Constructor T_Mime.create (Aowner: Tcomponent); Begin inherited Create (Aowner); f_attachment: = tList.create; end; (* @ @ @ @ @ @// destructor t_mime.destroy ; *) deStructor T_Mime.destroy; begin if f_attachment <> nil dam Try RemoveAlattachments; Except end; end; f_attachment.free; inherited destroy; (* @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 0000000701 *)

(* @ /// function t_mime.AttachFile (const filename: string): integer; *) function t_mime.AttachFile (const filename: string): integer; var t: t_attachment; data: TFileStream; begin t: = t_attachment.Create T. Kind: = 'Application / OCTET-stream'; t.encoding: = EC_BASE64; DATA: = NIL; Try Data: = TFileStream.create (filename, fmopenread); t.data:=data; data.free; Except data.free; t.free; raise; end; t.disposition: = 'attachment; filename = "' filename_of (filename) '"; result: = f_attachment.add (t); end; (* @ /// *) (* @ /// function t_mime.attachtetext (text: tstringlist): integer; *) function t_mime.attachtext (text: tstringlist): integer; var t_attachment; begin T: = t_attachment.create; T.Kind: = 'text / plain'; t.encoding: = EC_QUOTEDPRINTABLE; T.TEXT: = text; t.disposition: = '; result: = f_attachment.add (t); end; (* @ // / 000000060C *) (* @ /// procedure t_mime.RemoveAttachment (index: integer); *) procedure t_mime.RemoveAttachment (index: integer); begin if (index> = 0) and (f_attachment.count> index) then . Begin TObject (f_attachment [index]) free; f_attachment.delete (index); end; end; (* @ /// 0000000301 *) (* @ /// procedure t_mime.RemoveAllAttachments; *) procedure t_mime.RemoveAllAttachments; begin While f_attachment.count> 0 Do Begin Tobject (f_attachment [0]). free; f_attachment.delete (0); end; end; (* @ @ @ @ @ /// function t_mime.getnumberofattachments: integer ; *) function t_mime.getnumberofattachments: integer; begin result: = f_attachment.count; end; (* @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 0000000317 *)

(* @ /// procedure t_mime.action; *) procedure t_mime.action; var data, encode: TstringList; i, j, p: integer; attach: t_attachment; begin if f_mail = nil dam; boundary: = INTOSTR Round ((NOW-ENCODEDATE (1970, 1, 1)) * 86400)) INTTOHEX (my_ip_address, 8) '=='; DATA: = NIL; P: = - 1; Try Data: = TSTRINGLIST.CREATE f_mail.Header.Add ('mime-version: 1.0'); f_mail.Header.Add ('content-type: multipart / mix; bitchary = "' boundary '); f_mail.header.add (' content- TRANSFER-ENCODING: 7bit '); Data.assign (f_mail.body); if data.count> 0 Then Begin f_mail.body.clear; p: = attachtext (data); end; for i: = 0 to f_attachment.count -1 Do Begin attach: = t_attachment (f_attachment [i]); f_mail.body.add (''); f_mail.body.add ('-' boundary); f_mail.body.add ('content-type: ' attach.kind; if attach.disposition <>' 'TENF_MAIL.BODY.ADD (' content-disposition: ' attach.disposition); case attach.encoding of ec_base64: f_mail.body.add (' Content- TRA nsfer-encoding: base64 '); Ec_quotedprintable: f_mail.body.add (' content-transfer-encoding: quoted-printable '); end; f_mail.body.add (' '); case attach.encoding of (* @ / // ec_base64: *) ec_base64: begin encoded: = encode_base64 (attach.data); f_mail.Body.AddStrings (encoded); encoded.free; end; (* @ /// 0000000201 *) (* @ /// ec_quotedprintable : // Only for text! *) EC_QUOTEDPRINTABLE: Begin for J: = 0 to attach.text.count-1 do f_mail.body.add (Eight2seven_quoteprint (attach.text [j])); end; (* @

/// 0000000315 *) (* @ /// EC_NONE: // only for text! *) EC_NONE: Begin for j: = 0 to attach.text.count-1 do f_mail.body.add (Eight2seven_quoteprint (attach.text [J]); END; (* @ @ @ @ @ @ @ e; f_mail.body.add (''); f_mail.body.add ('-' bousary '-'); f_mail .action; if data.count> 0 THEN F_MAIL.BODY: = DATA; FINALLY DATA.FREE; Removeattachment (P); end; end; (* @ @ @ @ @ @ /// procedure t_mime.setmail (mail: TStringlist); *) procedure t_mime.SetMail (mail: TStringlist); (* @ /// procedure strip_header (const line: string; var field, data: string); *) procedure strip_header (const line: string; Var Field, Data: String; Var H: Integer; Begin H: = POS (':', line); if H> 0 Then Begin Field: = LowerCase (Copy (Line, 1, H-1)); DATA : = TRIM (Copy (Line, H 1, Length (Line)); END ELSE BEGIN Field: = '; DATA: ='; End; End; (* @ @ @ @ @ @ 00 00 00 1 1, J: Integer; S, Field, Data: String; Attach: t_attachment; begin boundary: = '; RemoveAlttachme NTS; (* @ /// PARSE Header Lines and search for mime bitchary *) i: = 0; while (i ') DO Begin Strip_Header Mail.Strings [I], Field, Data; (* @ /// if Field = 'Content-Type' Then *) if Field = 'Content-Type' Then Begin S: = COPY (Data, POS ('Boundary ', DATA), LENGTH (DATA); S: = Copy (S, POS (' ", S) 1, Length (s)); Boundary: = Copy (S, 1, POS ('", S) -1); END; (* @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ = = t_attachment.create; while true do begin inc;

(* ignore the empty line *) if i> = mail.count-1 Then Break; while (i '-' boundary) and (mail . Strings [i] <> - ' boundary ' - ') Do Begin attach.text.add (mail.strings [i]); inc (i); end; cas attach.encoding of (* @ / // EC_Base64: *) EC_Base64: Begin attach.data:=Decode_base64 (Attach.Text); attach.text: = nil; end; (* @ @ @ @ @ @ e _ qTedPrintable: *) EC_QUOTEDPRINTABLE : begin for j: = 0 to attach.text.count-1 do attach.text.strings [j]: = seven2eight_quoteprint (attach.text.strings [j]); end; (* @ @ @ @ @ @ @ @ @ on on :; End; if mail.strings [i] = '-' Boundary '-' TEN BREAK; (* end of mime *) if i> = mail.count-1 dam; if (attach.text. Count> 0) or (attach.data.size> 0) Then f_attachment.add (attach); attach: = t_attachment.create; inc (i); (* ignore the empty line *) if i> = mail.count- 1 Then Break; (* @ /// Parse Mime Block Header *) While (I ') Do Begin IF S [1] <>' Ten Strings [I], Field, Data) Else Data: = DATA S; if False Then Else IF Field = 'Content-Type' Ten Attach.kind: = DATA ELSE IF Field = 'Content-Disposition' Then Attach.disposition: = DATA (* @ /// Else if Field = 'Content-Transfer-Encoding' Then Begin *) Else if Field = 'Content-Transfer-Encoding' Then Begin Data: = LowerCase (DATA); if False Then Else if Data = 'Base64' Ten Attach.Encoding: = EC_BASE64 ELSE IF DATA =

'quoted-printable: = EC_QUOTEDPRINTABLE ELSE ATTACH.Encoding: = EC_NONE; END; (* @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 00m m .add (attach); end; (* @ /// 0000001b33 *) (* @ /// Function T_mime.Getattachment (index: integer): t_attachment; *) Function T_mime.getatchment (Index: Integer): t_attachment; begin IF index> f_attachment.count-1 Ten Result: = nil else result: = t_attachment (f_attachment [index]); end; (* @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ // / procedure Register; *) procedure Register; begin RegisterComponents ( 'TCP / IP', [t_finger]); RegisterComponents ( 'TCP / IP', [t_fingerD]); RegisterComponents ( 'TCP / IP', [t_http]); RegisterComponents ('TCP / IP', [T_FTP]); RegisterComponents ('TCP / IP', [T_LPR]); RegisterComponents ('TCP / IP', [T_SMTP]); Registercomponents ('TCP / IP', [T_mail]) Registercomponents ('TCP / IP', [T_NNTP]); RegisterComponents ('TCP / IP', [T_News]); Registercomponents ('TCP / IP', [T_TIME]); Registercomponents ('TCP / IP', [T_REXEC ]); Registercomponents ('TCP / IP', [T_RSH]); Registercomponents ('TCP / IP', [T_POP3]); RegisterComponents ('TCP / IP', [T_MIME]); END; (* @ /// *) ( * @ @ /// ositialization * begin lpr_count: = 0; End. (* @ /// *) (* @ @ @ @ 0001000011 *)

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

New Post(0)