2008-04-23 23:48:39 +03:00
|
|
|
{==============================================================================|
|
2008-04-24 09:59:26 +03:00
|
|
|
| Project : Delphree - Synapse | 001.004.000 |
|
2008-04-23 23:48:39 +03:00
|
|
|
|==============================================================================|
|
2008-04-24 09:40:58 +03:00
|
|
|
| Content: MIME support procedures and functions |
|
2008-04-23 23:48:39 +03:00
|
|
|
|==============================================================================|
|
|
|
|
| The contents of this file are subject to the Mozilla Public License Ver. 1.0 |
|
|
|
|
| (the "License"); you may not use this file except in compliance with the |
|
|
|
|
| License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ |
|
|
|
|
| |
|
|
|
|
| Software distributed under the License is distributed on an "AS IS" basis, |
|
|
|
|
| WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for |
|
|
|
|
| the specific language governing rights and limitations under the License. |
|
|
|
|
|==============================================================================|
|
|
|
|
| The Original Code is Synapse Delphi Library. |
|
|
|
|
|==============================================================================|
|
|
|
|
| The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
|
2008-04-24 09:47:56 +03:00
|
|
|
| Portions created by Lukas Gebauer are Copyright (c)2000,2001. |
|
2008-04-23 23:48:39 +03:00
|
|
|
| All Rights Reserved. |
|
|
|
|
|==============================================================================|
|
|
|
|
| Contributor(s): |
|
|
|
|
|==============================================================================|
|
|
|
|
| History: see HISTORY.HTM from distribution package |
|
|
|
|
| (Found at URL: http://www.ararat.cz/synapse/) |
|
|
|
|
|==============================================================================}
|
|
|
|
|
|
|
|
unit MIMEpart;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2008-04-24 09:59:26 +03:00
|
|
|
sysutils, classes, MIMEchar, SynaCode, SynaUtil, MIMEinLn;
|
2008-04-23 23:48:39 +03:00
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
TMimePrimary=(MP_TEXT,
|
|
|
|
MP_MULTIPART,
|
|
|
|
MP_MESSAGE,
|
|
|
|
MP_BINARY);
|
|
|
|
|
|
|
|
TMimeEncoding=(ME_7BIT,
|
|
|
|
ME_8BIT,
|
|
|
|
ME_QUOTED_PRINTABLE,
|
2008-04-24 09:40:58 +03:00
|
|
|
ME_BASE64,
|
|
|
|
ME_UU,
|
|
|
|
ME_XX);
|
2008-04-23 23:48:39 +03:00
|
|
|
|
|
|
|
TMimePart=class
|
|
|
|
private
|
|
|
|
FPrimary:string;
|
|
|
|
FEncoding:string;
|
|
|
|
FCharset:string;
|
|
|
|
procedure Setprimary(Value:string);
|
|
|
|
procedure SetEncoding(Value:string);
|
|
|
|
procedure SetCharset(Value:string);
|
|
|
|
protected
|
|
|
|
public
|
|
|
|
PrimaryCode:TMimePrimary;
|
|
|
|
EncodingCode:TMimeEncoding;
|
|
|
|
CharsetCode:TMimeChar;
|
|
|
|
TargetCharset:TMimeChar;
|
|
|
|
secondary:string;
|
|
|
|
description:string;
|
2008-04-24 09:47:56 +03:00
|
|
|
disposition:string;
|
2008-04-24 09:59:26 +03:00
|
|
|
contentID:string;
|
2008-04-23 23:48:39 +03:00
|
|
|
boundary:string;
|
|
|
|
FileName:string;
|
|
|
|
Lines:TStringList;
|
|
|
|
DecodedLines:TmemoryStream;
|
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure clear;
|
|
|
|
function ExtractPart(value:TStringList; BeginLine:integer):integer;
|
|
|
|
procedure DecodePart;
|
|
|
|
procedure EncodePart;
|
|
|
|
procedure MimeTypeFromExt(value:string);
|
|
|
|
property
|
|
|
|
Primary:string read FPrimary Write SetPrimary;
|
|
|
|
property
|
|
|
|
encoding:string read FEncoding write SetEncoding;
|
|
|
|
property
|
|
|
|
Charset:string read FCharset write SetCharset;
|
|
|
|
end;
|
|
|
|
|
|
|
|
const
|
2008-04-23 23:51:17 +03:00
|
|
|
MaxMimeType=25;
|
2008-04-23 23:48:39 +03:00
|
|
|
MimeType:array [0..MaxMimeType,0..2] of string=
|
|
|
|
(
|
2008-04-23 23:51:17 +03:00
|
|
|
('AU','audio','basic'),
|
|
|
|
('AVI','video','x-msvideo'),
|
|
|
|
('BMP','image','BMP'),
|
2008-04-23 23:48:39 +03:00
|
|
|
('DOC','application','MSWord'),
|
2008-04-23 23:51:17 +03:00
|
|
|
('EPS','application','Postscript'),
|
2008-04-23 23:48:39 +03:00
|
|
|
('GIF','image','GIF'),
|
|
|
|
('JPEG','image','JPEG'),
|
|
|
|
('JPG','image','JPEG'),
|
2008-04-23 23:51:17 +03:00
|
|
|
('MID','audio','midi'),
|
|
|
|
('MOV','video','quicktime'),
|
2008-04-23 23:48:39 +03:00
|
|
|
('MPEG','video','MPEG'),
|
|
|
|
('MPG','video','MPEG'),
|
2008-04-23 23:51:17 +03:00
|
|
|
('MP2','audio','mpeg'),
|
|
|
|
('MP3','audio','mpeg'),
|
2008-04-23 23:48:39 +03:00
|
|
|
('PDF','application','PDF'),
|
|
|
|
('PNG','image','PNG'),
|
|
|
|
('PS','application','Postscript'),
|
2008-04-23 23:51:17 +03:00
|
|
|
('QT','video','quicktime'),
|
|
|
|
('RA','audio','x-realaudio'),
|
2008-04-23 23:48:39 +03:00
|
|
|
('RTF','application','RTF'),
|
2008-04-23 23:51:17 +03:00
|
|
|
('SND','audio','basic'),
|
2008-04-23 23:48:39 +03:00
|
|
|
('TIF','image','TIFF'),
|
|
|
|
('TIFF','image','TIFF'),
|
2008-04-23 23:51:17 +03:00
|
|
|
('WAV','audio','x-wav'),
|
2008-04-23 23:48:39 +03:00
|
|
|
('WPD','application','Wordperfect5.1'),
|
|
|
|
('ZIP','application','ZIP')
|
|
|
|
);
|
|
|
|
|
2008-04-24 09:40:58 +03:00
|
|
|
function NormalizeHeader(value:TStringList;var index:integer):string;
|
2008-04-23 23:48:39 +03:00
|
|
|
function GenerateBoundary:string;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2008-04-24 09:40:58 +03:00
|
|
|
function NormalizeHeader(value:TStringList;var index:integer):string;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 09:40:58 +03:00
|
|
|
s,t:string;
|
|
|
|
n:integer;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 09:40:58 +03:00
|
|
|
s:=value[index];
|
|
|
|
inc(index);
|
|
|
|
if s<>''
|
|
|
|
then
|
|
|
|
while (value.Count-1) > index do
|
|
|
|
begin
|
|
|
|
t:=value[index];
|
|
|
|
if t=''
|
|
|
|
then break;
|
|
|
|
for n:=1 to length(t) do
|
|
|
|
if t[n]=#9
|
|
|
|
then t[n]:=' ';
|
|
|
|
if t[1]<>' '
|
|
|
|
then break
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
s:=s+' '+trim(t);
|
|
|
|
inc(index);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
result:=s;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
{TMIMEPart.Create}
|
|
|
|
Constructor TMIMEPart.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
Lines:=TStringList.Create;
|
|
|
|
DecodedLines:=TmemoryStream.create;
|
|
|
|
TargetCharset:=GetCurCP;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{TMIMEPart.Destroy}
|
|
|
|
Destructor TMIMEPart.Destroy;
|
|
|
|
begin
|
|
|
|
DecodedLines.free;
|
|
|
|
Lines.free;
|
|
|
|
inherited destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
{TMIMEPart.Clear}
|
|
|
|
procedure TMIMEPart.Clear;
|
|
|
|
begin
|
|
|
|
FPrimary:='';
|
|
|
|
FEncoding:='';
|
|
|
|
FCharset:='';
|
|
|
|
PrimaryCode:=MP_TEXT;
|
|
|
|
EncodingCode:=ME_7BIT;
|
|
|
|
CharsetCode:=ISO_8859_1;
|
|
|
|
TargetCharset:=GetCurCP;
|
|
|
|
secondary:='';
|
2008-04-24 09:47:56 +03:00
|
|
|
disposition:='';
|
2008-04-24 09:59:26 +03:00
|
|
|
contentID:='';
|
2008-04-23 23:48:39 +03:00
|
|
|
description:='';
|
|
|
|
boundary:='';
|
|
|
|
FileName:='';
|
|
|
|
Lines.clear;
|
|
|
|
DecodedLines.clear;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
{TMIMEPart.ExtractPart}
|
|
|
|
function TMIMEPart.ExtractPart(value:TStringList; BeginLine:integer):integer;
|
|
|
|
var
|
2008-04-23 23:51:17 +03:00
|
|
|
n,x,x1,x2:integer;
|
2008-04-23 23:48:39 +03:00
|
|
|
t:tstringlist;
|
|
|
|
s,su,b:string;
|
|
|
|
st,st2:string;
|
|
|
|
e:boolean;
|
2008-04-23 23:49:43 +03:00
|
|
|
fn:string;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
|
|
|
t:=tstringlist.create;
|
|
|
|
try
|
|
|
|
{defaults}
|
|
|
|
lines.clear;
|
|
|
|
primary:='text';
|
|
|
|
secondary:='plain';
|
|
|
|
description:='';
|
|
|
|
charset:='US-ASCII';
|
|
|
|
FileName:='';
|
|
|
|
encoding:='7BIT';
|
|
|
|
|
2008-04-23 23:49:43 +03:00
|
|
|
fn:='';
|
2008-04-23 23:48:39 +03:00
|
|
|
x:=beginline;
|
|
|
|
b:=boundary;
|
|
|
|
if b<>'' then
|
|
|
|
while value.count>x do
|
|
|
|
begin
|
|
|
|
s:=value[x];
|
|
|
|
inc(x);
|
|
|
|
if pos('--'+b,s)>0
|
|
|
|
then break;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{parse header}
|
|
|
|
while value.count>x do
|
|
|
|
begin
|
2008-04-24 09:40:58 +03:00
|
|
|
s:=normalizeheader(value,x);
|
2008-04-23 23:48:39 +03:00
|
|
|
if s=''
|
|
|
|
then break;
|
|
|
|
su:=uppercase(s);
|
|
|
|
if pos('CONTENT-TYPE:',su)=1 then
|
|
|
|
begin
|
|
|
|
st:=separateright(su,':');
|
|
|
|
st2:=separateleft(st,';');
|
|
|
|
primary:=separateleft(st2,'/');
|
|
|
|
secondary:=separateright(st2,'/');
|
2008-04-23 23:49:43 +03:00
|
|
|
if (secondary=primary) and (pos('/',st2)<1)
|
|
|
|
then secondary:='';
|
2008-04-23 23:48:39 +03:00
|
|
|
case primarycode of
|
|
|
|
MP_TEXT:
|
|
|
|
begin
|
|
|
|
charset:=uppercase(getparameter(s,'charset='));
|
|
|
|
end;
|
|
|
|
MP_MULTIPART:
|
|
|
|
begin
|
|
|
|
boundary:=getparameter(s,'boundary=');
|
|
|
|
end;
|
|
|
|
MP_MESSAGE:
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
MP_BINARY:
|
|
|
|
begin
|
2008-04-23 23:49:43 +03:00
|
|
|
filename:=getparameter(s,'name=');
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if pos('CONTENT-TRANSFER-ENCODING:',su)=1 then
|
|
|
|
begin
|
|
|
|
encoding:=separateright(su,':');
|
|
|
|
end;
|
|
|
|
if pos('CONTENT-DESCRIPTION:',su)=1 then
|
|
|
|
begin
|
|
|
|
description:=separateright(s,':');
|
|
|
|
end;
|
2008-04-23 23:49:43 +03:00
|
|
|
if pos('CONTENT-DISPOSITION:',su)=1 then
|
|
|
|
begin
|
2008-04-24 09:47:56 +03:00
|
|
|
disposition:=separateright(su,':');
|
|
|
|
disposition:=trim(separateleft(disposition,';'));
|
2008-04-23 23:49:43 +03:00
|
|
|
fn:=getparameter(s,'filename=');
|
|
|
|
end;
|
2008-04-24 09:59:26 +03:00
|
|
|
if pos('CONTENT-ID:',su)=1 then
|
|
|
|
begin
|
|
|
|
contentID:=separateright(s,':');
|
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-23 23:49:43 +03:00
|
|
|
if (primarycode=MP_BINARY) and (filename='')
|
|
|
|
then filename:=fn;
|
2008-04-24 09:40:58 +03:00
|
|
|
filename:=InlineDecode(filename,getCurCP);
|
|
|
|
filename:=extractfilename(filename);
|
2008-04-23 23:49:43 +03:00
|
|
|
|
2008-04-23 23:48:39 +03:00
|
|
|
x1:=x;
|
|
|
|
x2:=value.count-1;
|
|
|
|
if b<>'' then
|
|
|
|
begin
|
|
|
|
for n:=x to value.count-1 do
|
|
|
|
begin
|
|
|
|
x2:=n;
|
|
|
|
s:=value[n];
|
|
|
|
if pos('--'+b,s)>0
|
|
|
|
then begin
|
|
|
|
dec(x2);
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if primarycode=MP_MULTIPART then
|
|
|
|
begin
|
|
|
|
for n:=x to value.count-1 do
|
|
|
|
begin
|
|
|
|
s:=value[n];
|
|
|
|
if pos('--'+boundary,s)>0 then
|
|
|
|
begin
|
|
|
|
x1:=n;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
for n:=value.count-1 downto x do
|
|
|
|
begin
|
|
|
|
s:=value[n];
|
|
|
|
if pos('--'+boundary,s)>0 then
|
|
|
|
begin
|
|
|
|
x2:=n;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
for n:=x1 to x2 do
|
|
|
|
lines.add(value[n]);
|
|
|
|
result:=x2;
|
|
|
|
if primarycode=MP_MULTIPART then
|
|
|
|
begin
|
|
|
|
e:=false;
|
|
|
|
for n:=x2+1 to value.count-1 do
|
|
|
|
if pos('--'+boundary,value[n])>0 then
|
|
|
|
begin
|
|
|
|
e:=true;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
if not e
|
|
|
|
then result:=value.count-1;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
t.free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
{TMIMEPart.DecodePart}
|
|
|
|
procedure TMIMEPart.DecodePart;
|
|
|
|
const
|
|
|
|
CRLF=#$0D+#$0A;
|
|
|
|
var
|
|
|
|
n:integer;
|
|
|
|
s:string;
|
|
|
|
begin
|
|
|
|
decodedLines.Clear;
|
|
|
|
for n:=0 to lines.count-1 do
|
|
|
|
begin
|
|
|
|
s:=lines[n];
|
|
|
|
case EncodingCode of
|
|
|
|
ME_7BIT:
|
|
|
|
begin
|
|
|
|
s:=s+CRLF;
|
|
|
|
end;
|
|
|
|
ME_8BIT:
|
|
|
|
begin
|
|
|
|
s:=decodeChar(s,CharsetCode,TargetCharset);
|
|
|
|
s:=s+CRLF;
|
|
|
|
end;
|
|
|
|
ME_QUOTED_PRINTABLE:
|
|
|
|
begin
|
|
|
|
if s=''
|
|
|
|
then s:=CRLF
|
|
|
|
else
|
|
|
|
if s[length(s)]<>'='
|
|
|
|
then s:=s+CRLF;
|
|
|
|
s:=DecodeQuotedPrintable(s);
|
2008-04-23 23:49:43 +03:00
|
|
|
if PrimaryCode=MP_TEXT
|
|
|
|
then s:=decodeChar(s,CharsetCode,TargetCharset);
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
ME_BASE64:
|
|
|
|
begin
|
|
|
|
if s<>''
|
|
|
|
then s:=DecodeBase64(s);
|
|
|
|
if PrimaryCode=MP_TEXT
|
|
|
|
then s:=decodeChar(s,CharsetCode,TargetCharset);
|
|
|
|
end;
|
2008-04-24 09:40:58 +03:00
|
|
|
ME_UU:
|
|
|
|
begin
|
|
|
|
if s<>''
|
|
|
|
then s:=DecodeUU(s);
|
|
|
|
end;
|
|
|
|
ME_XX:
|
|
|
|
begin
|
|
|
|
if s<>''
|
|
|
|
then s:=DecodeXX(s);
|
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
Decodedlines.Write(pointer(s)^,length(s));
|
|
|
|
end;
|
|
|
|
decodedlines.Seek(0,soFromBeginning);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
{TMIMEPart.EncodePart}
|
|
|
|
procedure TMIMEPart.EncodePart;
|
|
|
|
var
|
|
|
|
l:TStringList;
|
|
|
|
s,buff:string;
|
|
|
|
n,x:integer;
|
|
|
|
begin
|
2008-04-24 09:40:58 +03:00
|
|
|
if EncodingCode=ME_UU
|
|
|
|
then encoding:='base64';
|
|
|
|
if EncodingCode=ME_XX
|
|
|
|
then encoding:='base64';
|
2008-04-23 23:48:39 +03:00
|
|
|
l:=tstringlist.create;
|
|
|
|
Lines.clear;
|
|
|
|
decodedlines.Seek(0,soFromBeginning);
|
|
|
|
try
|
|
|
|
case primarycode of
|
|
|
|
MP_MULTIPART,
|
|
|
|
MP_MESSAGE:
|
|
|
|
begin
|
|
|
|
lines.LoadFromStream(DecodedLines);
|
|
|
|
end;
|
|
|
|
MP_TEXT,
|
|
|
|
MP_BINARY:
|
|
|
|
if EncodingCode=ME_BASE64
|
|
|
|
then
|
|
|
|
begin
|
|
|
|
while decodedlines.Position<decodedlines.Size do
|
|
|
|
begin
|
|
|
|
Setlength(Buff,54);
|
|
|
|
s:='';
|
|
|
|
x:=Decodedlines.Read(pointer(Buff)^,54);
|
|
|
|
for n:=1 to x do
|
|
|
|
s:=s+Buff[n];
|
|
|
|
if PrimaryCode=MP_TEXT
|
|
|
|
then s:=decodeChar(s,TargetCharset,CharsetCode);
|
|
|
|
s:=EncodeBase64(s);
|
|
|
|
if x<>54
|
|
|
|
then s:=s+'=';
|
|
|
|
Lines.add(s);
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
l.LoadFromStream(DecodedLines);
|
|
|
|
for n:=0 to l.count-1 do
|
|
|
|
begin
|
|
|
|
s:=l[n];
|
|
|
|
if PrimaryCode=MP_TEXT
|
|
|
|
then s:=decodeChar(s,TargetCharset,CharsetCode);
|
|
|
|
s:=EncodeQuotedPrintable(s);
|
|
|
|
Lines.add(s);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end;
|
|
|
|
Lines.add('');
|
|
|
|
lines.insert(0,'');
|
|
|
|
if secondary='' then
|
|
|
|
case PrimaryCode of
|
|
|
|
MP_TEXT: secondary:='plain';
|
|
|
|
MP_MULTIPART: secondary:='mixed';
|
|
|
|
MP_MESSAGE: secondary:='rfc822';
|
|
|
|
MP_BINARY: secondary:='octet-stream';
|
|
|
|
end;
|
|
|
|
if description<>''
|
|
|
|
then lines.insert(0,'Content-Description: '+Description);
|
2008-04-24 09:47:56 +03:00
|
|
|
if disposition<>'' then
|
|
|
|
begin
|
|
|
|
s:='';
|
|
|
|
if filename<>''
|
|
|
|
then s:='; filename="'+filename+'"';
|
|
|
|
lines.insert(0,'Content-Disposition: '+lowercase(disposition)+s);
|
|
|
|
end;
|
2008-04-24 09:59:26 +03:00
|
|
|
if contentID<>''
|
|
|
|
then lines.insert(0,'Content-ID: '+contentID);
|
2008-04-24 09:47:56 +03:00
|
|
|
|
2008-04-23 23:48:39 +03:00
|
|
|
case EncodingCode of
|
|
|
|
ME_7BIT: s:='7bit';
|
|
|
|
ME_8BIT: s:='8bit';
|
|
|
|
ME_QUOTED_PRINTABLE: s:='Quoted-printable';
|
|
|
|
ME_BASE64: s:='Base64';
|
|
|
|
end;
|
|
|
|
case PrimaryCode of
|
|
|
|
MP_TEXT,
|
|
|
|
MP_BINARY: lines.insert(0,'Content-Transfer-Encoding: '+s);
|
|
|
|
end;
|
|
|
|
case PrimaryCode of
|
|
|
|
MP_TEXT: s:=primary+'/'+secondary+'; charset='+GetIDfromCP(charsetcode);
|
|
|
|
MP_MULTIPART: s:=primary+'/'+secondary+'; boundary="'+boundary+'"';
|
|
|
|
MP_MESSAGE: s:=primary+'/'+secondary+'';
|
|
|
|
MP_BINARY: s:=primary+'/'+secondary+'; name="'+FileName+'"';
|
|
|
|
end;
|
|
|
|
lines.insert(0,'Content-type: '+s);
|
|
|
|
finally
|
|
|
|
l.free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
{TMIMEPart.MimeTypeFromExt}
|
|
|
|
procedure TMIMEPart.MimeTypeFromExt(value:string);
|
|
|
|
var
|
|
|
|
s:string;
|
|
|
|
n:integer;
|
|
|
|
begin
|
|
|
|
primary:='';
|
|
|
|
secondary:='';
|
2008-04-24 09:47:56 +03:00
|
|
|
s:=uppercase(extractfileext(value));
|
2008-04-23 23:48:39 +03:00
|
|
|
if s=''
|
|
|
|
then s:=uppercase(value);
|
2008-04-24 09:59:26 +03:00
|
|
|
s:=separateright(s,'.');
|
2008-04-23 23:48:39 +03:00
|
|
|
for n:=0 to MaxMimeType do
|
|
|
|
if MimeType[n,0]=s then
|
|
|
|
begin
|
|
|
|
primary:=MimeType[n,1];
|
|
|
|
secondary:=MimeType[n,2];
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
if primary=''
|
|
|
|
then primary:='application';
|
|
|
|
if secondary=''
|
|
|
|
then secondary:='mixed';
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
{TMIMEPart.Setprimary}
|
|
|
|
procedure TMIMEPart.Setprimary(Value:string);
|
|
|
|
var
|
|
|
|
s:string;
|
|
|
|
begin
|
|
|
|
Fprimary:=Value;
|
|
|
|
s:=uppercase(Value);
|
|
|
|
PrimaryCode:=MP_BINARY;
|
|
|
|
if Pos('TEXT',s)=1
|
|
|
|
then PrimaryCode:=MP_TEXT;
|
|
|
|
if Pos('MULTIPART',s)=1
|
|
|
|
then PrimaryCode:=MP_MULTIPART;
|
|
|
|
if Pos('MESSAGE',s)=1
|
|
|
|
then PrimaryCode:=MP_MESSAGE;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{TMIMEPart.SetEncoding}
|
|
|
|
procedure TMIMEPart.SetEncoding(Value:string);
|
|
|
|
var
|
|
|
|
s:string;
|
|
|
|
begin
|
|
|
|
FEncoding:=Value;
|
|
|
|
s:=uppercase(Value);
|
|
|
|
EncodingCode:=ME_7BIT;
|
|
|
|
if Pos('8BIT',s)=1
|
|
|
|
then EncodingCode:=ME_8BIT;
|
|
|
|
if Pos('QUOTED-PRINTABLE',s)=1
|
|
|
|
then EncodingCode:=ME_QUOTED_PRINTABLE;
|
|
|
|
if Pos('BASE64',s)=1
|
|
|
|
then EncodingCode:=ME_BASE64;
|
2008-04-24 09:40:58 +03:00
|
|
|
if Pos('X-UU',s)=1
|
|
|
|
then EncodingCode:=ME_UU;
|
|
|
|
if Pos('X-XX',s)=1
|
|
|
|
then EncodingCode:=ME_XX;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{TMIMEPart.SetCharset}
|
|
|
|
procedure TMIMEPart.SetCharset(Value:string);
|
|
|
|
begin
|
|
|
|
FCharset:=Value;
|
|
|
|
CharsetCode:=GetCPfromID(value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
{GenerateBoundary}
|
|
|
|
function GenerateBoundary:string;
|
|
|
|
var
|
|
|
|
x:integer;
|
|
|
|
begin
|
|
|
|
randomize;
|
|
|
|
x:=random(maxint);
|
|
|
|
result:='----'+Inttohex(x,8)+'_Synapse_message_boundary';
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
begin
|
|
|
|
exit;
|
|
|
|
asm
|
|
|
|
db 'Synapse MIME messages encoding and decoding library by Lukas Gebauer',0
|
|
|
|
end;
|
|
|
|
end.
|