王朝网络
分享
 
 
 

TCP/IP(九)

王朝delphi·作者佚名  2006-01-08
宽屏版  字体: |||超大  

(*@\\\0000000B01*)

(*@\\\0000000801*)

(*@/// class t_news(t_mailnews) *)

(*@/// 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;

(*@\\\000000030F*)

(*@/// 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;

(*@\\\0000000603*)

(*@/// 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 then

s:=s+',';

f_message.add(s);

if i>=f_newsgroups.count then BREAK;

s:=' ';

end;

if f_organization<>'' then f_message.add(f_organization);

inherited action;

f_nntp.login;

f_nntp.news:=f_message;

f_nntp.PostArticle;

f_nntp.logout;

f_message.clear;

end;

(*@\\\*)

(*@\\\0000000401*)

(*@/// 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;

begin

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 then

TMemoryStream(f_data).clear

else begin

f_text.clear;

TMemoryStream(f_data).LoadFromStream(value);

end;

end;

(*@\\\000000041A*)

(*@\\\*)

(*@/// class t_mime(TComponent) *)

(*@/// constructor t_mime.Create(Aowner:TComponent); *)

constructor t_mime.Create(Aowner:TComponent);

begin

inherited Create(AOwner);

f_attachment:=TList.Create;

end;

(*@\\\000000040F*)

(*@/// destructor t_mime.Destroy; *)

destructor t_mime.Destroy;

begin

if f_attachment<>NIL then begin

try

RemoveAllAttachments;

except

end;

end;

f_attachment.free;

inherited Destroy;

end;

(*@\\\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.AttachText(text: TStringList):integer; *)

function t_mime.AttachText(text: TStringList):integer;

var

t: 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;

(*@\\\000000031E*)

(*@/// 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, encoded: TStringList;

i,j,p: integer;

attach: t_attachment;

begin

if f_mail=NIL then EXIT;

boundary:=inttostr(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/mixed; boundary="'+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<>'' then

f_mail.Body.Add('Content-Disposition: '+attach.disposition);

case attach.encoding of

ec_base64: f_mail.Body.Add('Content-Transfer-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;

(*@\\\0000000403*)

end;

end;

f_mail.Body.Add('');

f_mail.Body.Add('--'+boundary+'--');

f_mail.action;

if data.count>0 then

f_mail.body:=data;

finally

data.free;

RemoveAttachment(p);

end;

end;

(*@\\\0000002201*)

(*@/// 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;

(*@\\\0000000B12*)

var

i,j: integer;

s,field,data: string;

attach: t_attachment;

begin

boundary:='';

RemoveAllAttachments;

(*@/// parse header lines and search for mime boundary *)

i:=0;

while (i<mail.count-1) and (mail.strings[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;

(*@\\\0000000201*)

inc(i);

end;

(*@\\\0000000401*)

attach:=t_attachment.create;

while true do begin

inc(i); (* ignore the empty line *)

if i>=mail.count-1 then BREAK;

while (i<mail.count-1) and (mail.strings[i]<>'--'+boundary) and

(mail.strings[i]<>'--'+boundary+'--') do begin

attach.text.add(mail.strings[i]);

inc(i);

end;

case attach.encoding of

(*@/// ec_base64: *)

ec_base64: begin

attach.data:=decode_base64(attach.text);

attach.text:=NIL;

end;

(*@\\\0000000301*)

(*@/// ec_quotedprintable: *)

ec_quotedprintable: begin

for j:=0 to attach.text.count-1 do

attach.text.strings[j]:=seven2eight_quoteprint(attach.text.strings[j]);

end;

(*@\\\0000000301*)

ec_none: ;

end;

if mail.strings[i]='--'+boundary+'--' then BREAK; (* end of mime *)

if i>=mail.count-1 then BREAK;

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<mail.count-1) and (mail.strings[i]<>'') do begin

if s[1]<>' ' then

strip_header(mail.strings[i],field,data)

else

data:=data+s;

if false then

else if field='content-type' then 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' then

attach.encoding:=ec_base64

else if data='quoted-printable' then

attach.encoding:=ec_quotedprintable

else

attach.encoding:=ec_none;

end;

(*@\\\0000000716*)

inc(i);

end;

(*@\\\0000000901*)

end;

f_attachment.add(attach);

end;

(*@\\\0000001B33*)

(*@/// function t_mime.GetAttachment(index: integer):t_attachment; *)

function t_mime.GetAttachment(index: integer):t_attachment;

begin

if index>f_attachment.count-1 then

result:=NIL

else

result:=t_attachment(f_attachment[index]);

end;

(*@\\\0000000306*)

(*@\\\0000000501*)

(*@/// 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;

(*@\\\*)

(*@\\\0000003114*)

(*@/// initialization *)

begin

lpr_count:=0;

end.

(*@\\\*)

(*@\\\0001000011*)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有