2008-04-23 23:48:39 +03:00
|
|
|
{==============================================================================|
|
2008-04-24 10:25:18 +03:00
|
|
|
| Project : Ararat Synapse | 002.002.003 |
|
2008-04-23 23:48:39 +03:00
|
|
|
|==============================================================================|
|
|
|
|
| Content: MIME message object |
|
|
|
|
|==============================================================================|
|
2008-04-24 10:22:17 +03:00
|
|
|
| Copyright (c)1999-2003, Lukas Gebauer |
|
2008-04-24 10:20:39 +03:00
|
|
|
| All rights reserved. |
|
2008-04-23 23:48:39 +03:00
|
|
|
| |
|
2008-04-24 10:20:39 +03:00
|
|
|
| Redistribution and use in source and binary forms, with or without |
|
|
|
|
| modification, are permitted provided that the following conditions are met: |
|
|
|
|
| |
|
|
|
|
| Redistributions of source code must retain the above copyright notice, this |
|
|
|
|
| list of conditions and the following disclaimer. |
|
|
|
|
| |
|
|
|
|
| Redistributions in binary form must reproduce the above copyright notice, |
|
|
|
|
| this list of conditions and the following disclaimer in the documentation |
|
|
|
|
| and/or other materials provided with the distribution. |
|
|
|
|
| |
|
|
|
|
| Neither the name of Lukas Gebauer nor the names of its contributors may |
|
|
|
|
| be used to endorse or promote products derived from this software without |
|
|
|
|
| specific prior written permission. |
|
|
|
|
| |
|
|
|
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
|
|
|
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
|
|
|
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
|
|
|
| ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR |
|
|
|
|
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
|
|
|
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
|
|
|
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
|
|
|
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
|
|
|
| LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
|
|
|
| OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
|
|
|
|
| DAMAGE. |
|
2008-04-23 23:48:39 +03:00
|
|
|
|==============================================================================|
|
|
|
|
| The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
|
2008-04-24 10:22:17 +03:00
|
|
|
| Portions created by Lukas Gebauer are Copyright (c)2000-2003. |
|
2008-04-23 23:48:39 +03:00
|
|
|
| All Rights Reserved. |
|
|
|
|
|==============================================================================|
|
|
|
|
| Contributor(s): |
|
|
|
|
|==============================================================================|
|
2008-04-24 10:05:26 +03:00
|
|
|
| History: see HISTORY.HTM From distribution package |
|
2008-04-23 23:48:39 +03:00
|
|
|
| (Found at URL: http://www.ararat.cz/synapse/) |
|
|
|
|
|==============================================================================}
|
|
|
|
|
2008-04-24 10:25:18 +03:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE DELPHI}
|
|
|
|
{$ENDIF}
|
|
|
|
{$H+}
|
|
|
|
|
|
|
|
unit mimemess;
|
2008-04-23 23:48:39 +03:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2008-04-24 10:05:26 +03:00
|
|
|
Classes, SysUtils,
|
2008-04-24 10:25:18 +03:00
|
|
|
mimepart, synachar, synautil, mimeinln;
|
2008-04-23 23:48:39 +03:00
|
|
|
|
|
|
|
type
|
2008-04-24 10:05:26 +03:00
|
|
|
TMessHeader = class(TObject)
|
|
|
|
private
|
|
|
|
FFrom: string;
|
|
|
|
FToList: TStringList;
|
2008-04-24 10:12:01 +03:00
|
|
|
FCCList: TStringList;
|
2008-04-24 10:05:26 +03:00
|
|
|
FSubject: string;
|
|
|
|
FOrganization: string;
|
2008-04-24 10:07:45 +03:00
|
|
|
FCustomHeaders: TStringList;
|
2008-04-24 10:12:01 +03:00
|
|
|
FDate: TDateTime;
|
2008-04-24 10:13:22 +03:00
|
|
|
FXMailer: string;
|
2008-04-24 10:25:18 +03:00
|
|
|
FCharsetCode: TMimeChar;
|
2008-04-24 10:05:26 +03:00
|
|
|
public
|
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure Clear;
|
2008-04-24 10:20:39 +03:00
|
|
|
procedure EncodeHeaders(const Value: TStrings);
|
|
|
|
procedure DecodeHeaders(const Value: TStrings);
|
2008-04-24 10:12:01 +03:00
|
|
|
function FindHeader(Value: string): string;
|
2008-04-24 10:20:39 +03:00
|
|
|
procedure FindHeaderList(Value: string; const HeaderList: TStrings);
|
2008-04-24 10:05:26 +03:00
|
|
|
published
|
|
|
|
property From: string read FFrom Write FFrom;
|
2008-04-24 10:07:45 +03:00
|
|
|
property ToList: TStringList read FToList;
|
2008-04-24 10:12:01 +03:00
|
|
|
property CCList: TStringList read FCCList;
|
2008-04-24 10:05:26 +03:00
|
|
|
property Subject: string read FSubject Write FSubject;
|
|
|
|
property Organization: string read FOrganization Write FOrganization;
|
2008-04-24 10:07:45 +03:00
|
|
|
property CustomHeaders: TStringList read FCustomHeaders;
|
2008-04-24 10:12:01 +03:00
|
|
|
property Date: TDateTime read FDate Write FDate;
|
2008-04-24 10:13:22 +03:00
|
|
|
property XMailer: string read FXMailer Write FXMailer;
|
2008-04-24 10:25:18 +03:00
|
|
|
property CharsetCode: TMimeChar read FCharsetCode Write FCharsetCode;
|
2008-04-24 10:05:26 +03:00
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
TMimeMess = class(TObject)
|
2008-04-23 23:48:39 +03:00
|
|
|
private
|
2008-04-24 10:20:39 +03:00
|
|
|
FMessagePart: TMimePart;
|
2008-04-24 10:05:26 +03:00
|
|
|
FLines: TStringList;
|
|
|
|
FHeader: TMessHeader;
|
2008-04-23 23:48:39 +03:00
|
|
|
public
|
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure Clear;
|
2008-04-24 10:20:39 +03:00
|
|
|
function AddPart(const PartParent: TMimePart): TMimePart;
|
|
|
|
function AddPartMultipart(const MultipartType: String; const PartParent: TMimePart): TMimePart;
|
|
|
|
function AddPartText(const Value: TStrings; const PartParent: TMimePart): TMimepart;
|
|
|
|
function AddPartHTML(const Value: TStrings; const PartParent: TMimePart): TMimepart;
|
|
|
|
function AddPartTextFromFile(const FileName: String; const PartParent: TMimePart): TMimepart;
|
|
|
|
function AddPartHTMLFromFile(const FileName: String; const PartParent: TMimePart): TMimepart;
|
|
|
|
function AddPartBinary(const Stream: TStream; const FileName: string; const PartParent: TMimePart): TMimepart;
|
|
|
|
function AddPartBinaryFromFile(const FileName: string; const PartParent: TMimePart): TMimepart;
|
|
|
|
function AddPartHTMLBinary(const Stream: TStream; const FileName, Cid: string; const PartParent: TMimePart): TMimepart;
|
|
|
|
function AddPartHTMLBinaryFromFile(const FileName, Cid: string; const PartParent: TMimePart): TMimepart;
|
2008-04-23 23:48:39 +03:00
|
|
|
procedure EncodeMessage;
|
|
|
|
procedure DecodeMessage;
|
2008-04-24 10:05:26 +03:00
|
|
|
published
|
2008-04-24 10:20:39 +03:00
|
|
|
property MessagePart: TMimePart read FMessagePart;
|
2008-04-24 10:07:45 +03:00
|
|
|
property Lines: TStringList read FLines;
|
|
|
|
property Header: TMessHeader read FHeader;
|
2008-04-24 10:05:26 +03:00
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
|
|
|
constructor TMessHeader.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
FToList := TStringList.Create;
|
2008-04-24 10:12:01 +03:00
|
|
|
FCCList := TStringList.Create;
|
2008-04-24 10:07:45 +03:00
|
|
|
FCustomHeaders := TStringList.Create;
|
2008-04-24 10:25:18 +03:00
|
|
|
FCharsetCode := GetCurCP;
|
2008-04-24 10:05:26 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TMessHeader.Destroy;
|
|
|
|
begin
|
2008-04-24 10:07:45 +03:00
|
|
|
FCustomHeaders.Free;
|
2008-04-24 10:12:01 +03:00
|
|
|
FCCList.Free;
|
2008-04-24 10:05:26 +03:00
|
|
|
FToList.Free;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
procedure TMessHeader.Clear;
|
|
|
|
begin
|
|
|
|
FFrom := '';
|
|
|
|
FToList.Clear;
|
2008-04-24 10:12:01 +03:00
|
|
|
FCCList.Clear;
|
2008-04-24 10:05:26 +03:00
|
|
|
FSubject := '';
|
|
|
|
FOrganization := '';
|
2008-04-24 10:07:45 +03:00
|
|
|
FCustomHeaders.Clear;
|
2008-04-24 10:12:01 +03:00
|
|
|
FDate := 0;
|
2008-04-24 10:13:22 +03:00
|
|
|
FXMailer := '';
|
2008-04-24 10:07:45 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
procedure TMessHeader.EncodeHeaders(const Value: TStrings);
|
2008-04-24 10:07:45 +03:00
|
|
|
var
|
|
|
|
n: Integer;
|
2008-04-24 10:13:22 +03:00
|
|
|
s: string;
|
2008-04-24 10:07:45 +03:00
|
|
|
begin
|
2008-04-24 10:12:01 +03:00
|
|
|
if FDate = 0 then
|
|
|
|
FDate := Now;
|
2008-04-24 10:07:45 +03:00
|
|
|
for n := FCustomHeaders.Count - 1 downto 0 do
|
|
|
|
if FCustomHeaders[n] <> '' then
|
|
|
|
Value.Insert(0, FCustomHeaders[n]);
|
2008-04-24 10:13:22 +03:00
|
|
|
if FXMailer = '' then
|
2008-04-24 10:22:17 +03:00
|
|
|
Value.Insert(0, 'X-mailer: Synapse - Delphi & Kylix TCP/IP library by Lukas Gebauer')
|
2008-04-24 10:13:22 +03:00
|
|
|
else
|
2008-04-24 10:22:17 +03:00
|
|
|
Value.Insert(0, 'X-mailer: ' + FXMailer);
|
2008-04-24 10:07:45 +03:00
|
|
|
Value.Insert(0, 'MIME-Version: 1.0 (produced by Synapse)');
|
|
|
|
if FOrganization <> '' then
|
2008-04-24 10:25:18 +03:00
|
|
|
Value.Insert(0, 'Organization: ' + InlineCodeEx(FOrganization, FCharsetCode));
|
2008-04-24 10:13:22 +03:00
|
|
|
s := '';
|
2008-04-24 10:12:01 +03:00
|
|
|
for n := 0 to FCCList.Count - 1 do
|
2008-04-24 10:13:22 +03:00
|
|
|
if s = '' then
|
2008-04-24 10:25:18 +03:00
|
|
|
s := InlineEmailEx(FCCList[n], FCharsetCode)
|
2008-04-24 10:13:22 +03:00
|
|
|
else
|
2008-04-24 10:25:18 +03:00
|
|
|
s := s + ' , ' + InlineEmailEx(FCCList[n], FCharsetCode);
|
2008-04-24 10:13:22 +03:00
|
|
|
if s <> '' then
|
|
|
|
Value.Insert(0, 'CC: ' + s);
|
2008-04-24 10:12:01 +03:00
|
|
|
Value.Insert(0, 'Date: ' + Rfc822DateTime(FDate));
|
2008-04-24 10:07:45 +03:00
|
|
|
if FSubject <> '' then
|
2008-04-24 10:25:18 +03:00
|
|
|
Value.Insert(0, 'Subject: ' + InlineCodeEx(FSubject, FCharsetCode));
|
2008-04-24 10:13:22 +03:00
|
|
|
s := '';
|
2008-04-24 10:07:45 +03:00
|
|
|
for n := 0 to FToList.Count - 1 do
|
2008-04-24 10:13:22 +03:00
|
|
|
if s = '' then
|
2008-04-24 10:25:18 +03:00
|
|
|
s := InlineEmailEx(FToList[n], FCharsetCode)
|
2008-04-24 10:13:22 +03:00
|
|
|
else
|
2008-04-24 10:25:18 +03:00
|
|
|
s := s + ' , ' + InlineEmailEx(FToList[n], FCharsetCode);
|
2008-04-24 10:13:22 +03:00
|
|
|
if s <> '' then
|
|
|
|
Value.Insert(0, 'To: ' + s);
|
2008-04-24 10:25:18 +03:00
|
|
|
Value.Insert(0, 'From: ' + InlineEmailEx(FFrom, FCharsetCode));
|
2008-04-24 10:07:45 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
procedure TMessHeader.DecodeHeaders(const Value: TStrings);
|
2008-04-24 10:07:45 +03:00
|
|
|
var
|
2008-04-24 10:12:01 +03:00
|
|
|
s, t: string;
|
2008-04-24 10:07:45 +03:00
|
|
|
x: Integer;
|
|
|
|
cp: TMimeChar;
|
|
|
|
begin
|
2008-04-24 10:25:18 +03:00
|
|
|
cp := FCharsetCode;
|
2008-04-24 10:07:45 +03:00
|
|
|
Clear;
|
|
|
|
x := 0;
|
|
|
|
while Value.Count > x do
|
|
|
|
begin
|
|
|
|
s := NormalizeHeader(Value, x);
|
|
|
|
if s = '' then
|
|
|
|
Break;
|
2008-04-24 10:13:22 +03:00
|
|
|
if Pos('X-MAILER:', UpperCase(s)) = 1 then
|
|
|
|
begin
|
|
|
|
FXMailer := SeparateRight(s, ':');
|
|
|
|
continue;
|
|
|
|
end;
|
2008-04-24 10:07:45 +03:00
|
|
|
if Pos('FROM:', UpperCase(s)) = 1 then
|
|
|
|
begin
|
|
|
|
FFrom := InlineDecode(SeparateRight(s, ':'), cp);
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
if Pos('SUBJECT:', UpperCase(s)) = 1 then
|
|
|
|
begin
|
|
|
|
FSubject := InlineDecode(SeparateRight(s, ':'), cp);
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
if Pos('ORGANIZATION:', UpperCase(s)) = 1 then
|
|
|
|
begin
|
|
|
|
FOrganization := InlineDecode(SeparateRight(s, ':'), cp);
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
if Pos('TO:', UpperCase(s)) = 1 then
|
|
|
|
begin
|
2008-04-24 10:12:01 +03:00
|
|
|
s := SeparateRight(s, ':');
|
|
|
|
repeat
|
2008-04-24 10:25:18 +03:00
|
|
|
t := InlineDecode(FetchEx(s, ',', '"'), cp);
|
2008-04-24 10:12:01 +03:00
|
|
|
if t <> '' then
|
|
|
|
FToList.Add(t);
|
|
|
|
until s = '';
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
if Pos('CC:', UpperCase(s)) = 1 then
|
|
|
|
begin
|
|
|
|
s := SeparateRight(s, ':');
|
|
|
|
repeat
|
2008-04-24 10:25:18 +03:00
|
|
|
t := InlineDecode(FetchEx(s, ',', '"'), cp);
|
2008-04-24 10:12:01 +03:00
|
|
|
if t <> '' then
|
|
|
|
FCCList.Add(t);
|
|
|
|
until s = '';
|
|
|
|
continue;
|
|
|
|
end;
|
|
|
|
if Pos('DATE:', UpperCase(s)) = 1 then
|
|
|
|
begin
|
|
|
|
FDate := DecodeRfcDateTime(SeparateRight(s, ':'));
|
2008-04-24 10:07:45 +03:00
|
|
|
continue;
|
|
|
|
end;
|
2008-04-24 10:18:26 +03:00
|
|
|
if Pos('MIME-VERSION:', UpperCase(s)) = 1 then
|
|
|
|
continue;
|
|
|
|
if Pos('CONTENT-TYPE:', UpperCase(s)) = 1 then
|
|
|
|
continue;
|
|
|
|
if Pos('CONTENT-DESCRIPTION:', UpperCase(s)) = 1 then
|
|
|
|
continue;
|
|
|
|
if Pos('CONTENT-DISPOSITION:', UpperCase(s)) = 1 then
|
|
|
|
continue;
|
|
|
|
if Pos('CONTENT-ID:', UpperCase(s)) = 1 then
|
|
|
|
continue;
|
|
|
|
if Pos('CONTENT-TRANSFER-ENCODING:', UpperCase(s)) = 1 then
|
|
|
|
continue;
|
2008-04-24 10:07:45 +03:00
|
|
|
FCustomHeaders.Add(s);
|
|
|
|
end;
|
2008-04-24 10:05:26 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
function TMessHeader.FindHeader(Value: string): string;
|
|
|
|
var
|
|
|
|
n: integer;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
for n := 0 to FCustomHeaders.Count - 1 do
|
2008-04-24 10:18:26 +03:00
|
|
|
if Pos(UpperCase(Value), UpperCase(FCustomHeaders[n])) = 1 then
|
2008-04-24 10:12:01 +03:00
|
|
|
begin
|
|
|
|
Result := SeparateRight(FCustomHeaders[n], ':');
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
procedure TMessHeader.FindHeaderList(Value: string; const HeaderList: TStrings);
|
2008-04-24 10:12:01 +03:00
|
|
|
var
|
|
|
|
n: integer;
|
|
|
|
begin
|
|
|
|
HeaderList.Clear;
|
|
|
|
for n := 0 to FCustomHeaders.Count - 1 do
|
2008-04-24 10:18:26 +03:00
|
|
|
if Pos(UpperCase(Value), UpperCase(FCustomHeaders[n])) = 1 then
|
2008-04-24 10:12:01 +03:00
|
|
|
begin
|
|
|
|
HeaderList.Add(SeparateRight(FCustomHeaders[n], ':'));
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
constructor TMimeMess.Create;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
|
|
|
inherited Create;
|
2008-04-24 10:20:39 +03:00
|
|
|
FMessagePart := TMimePart.Create;
|
2008-04-24 10:05:26 +03:00
|
|
|
FLines := TStringList.Create;
|
|
|
|
FHeader := TMessHeader.Create;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:05:26 +03:00
|
|
|
destructor TMimeMess.Destroy;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
FMessagePart.Free;
|
2008-04-24 10:05:26 +03:00
|
|
|
FHeader.Free;
|
2008-04-24 10:20:39 +03:00
|
|
|
FLines.Free;
|
2008-04-24 10:05:26 +03:00
|
|
|
inherited Destroy;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
2008-04-23 23:48:39 +03:00
|
|
|
procedure TMimeMess.Clear;
|
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
FMessagePart.Clear;
|
|
|
|
FLines.Clear;
|
2008-04-24 10:05:26 +03:00
|
|
|
FHeader.Clear;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
function TMimeMess.AddPart(const PartParent: TMimePart): TMimePart;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
if PartParent = nil then
|
|
|
|
Result := FMessagePart
|
|
|
|
else
|
|
|
|
Result := PartParent.AddSubPart;
|
|
|
|
Result.Clear;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
function TMimeMess.AddPartMultipart(const MultipartType: String; const PartParent: TMimePart): TMimePart;
|
|
|
|
begin
|
|
|
|
Result := AddPart(PartParent);
|
|
|
|
with Result do
|
|
|
|
begin
|
|
|
|
Primary := 'Multipart';
|
|
|
|
Secondary := MultipartType;
|
|
|
|
Description := 'Multipart message';
|
|
|
|
Boundary := GenerateBoundary;
|
|
|
|
EncodePartHeader;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TMimeMess.AddPartText(const Value: TStrings; const PartParent: TMimePart): TMimepart;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
Result := AddPart(PartParent);
|
|
|
|
with Result do
|
2008-04-24 10:05:26 +03:00
|
|
|
begin
|
|
|
|
Value.SaveToStream(DecodedLines);
|
|
|
|
Primary := 'text';
|
|
|
|
Secondary := 'plain';
|
|
|
|
Description := 'Message text';
|
|
|
|
Disposition := 'inline';
|
|
|
|
CharsetCode := IdealCharsetCoding(Value.Text, TargetCharset,
|
|
|
|
[ISO_8859_1, ISO_8859_2, ISO_8859_3, ISO_8859_4, ISO_8859_5,
|
|
|
|
ISO_8859_6, ISO_8859_7, ISO_8859_8, ISO_8859_9, ISO_8859_10]);
|
|
|
|
EncodingCode := ME_QUOTED_PRINTABLE;
|
|
|
|
EncodePart;
|
2008-04-24 10:20:39 +03:00
|
|
|
EncodePartHeader;
|
2008-04-24 10:05:26 +03:00
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
function TMimeMess.AddPartHTML(const Value: TStrings; const PartParent: TMimePart): TMimepart;
|
2008-04-24 09:47:56 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
Result := AddPart(PartParent);
|
|
|
|
with Result do
|
2008-04-24 10:05:26 +03:00
|
|
|
begin
|
|
|
|
Value.SaveToStream(DecodedLines);
|
|
|
|
Primary := 'text';
|
|
|
|
Secondary := 'html';
|
|
|
|
Description := 'HTML text';
|
|
|
|
Disposition := 'inline';
|
|
|
|
CharsetCode := UTF_8;
|
|
|
|
EncodingCode := ME_QUOTED_PRINTABLE;
|
|
|
|
EncodePart;
|
2008-04-24 10:20:39 +03:00
|
|
|
EncodePartHeader;
|
2008-04-24 10:05:26 +03:00
|
|
|
end;
|
2008-04-24 09:47:56 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
function TMimeMess.AddPartTextFromFile(const FileName: String; const PartParent: TMimePart): TMimepart;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:20:39 +03:00
|
|
|
tmp: TStrings;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
tmp := TStringList.Create;
|
|
|
|
try
|
|
|
|
tmp.LoadFromFile(FileName);
|
|
|
|
Result := AddPartText(tmp, PartParent);
|
|
|
|
Finally
|
|
|
|
tmp.Free;
|
2008-04-24 10:05:26 +03:00
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
function TMimeMess.AddPartHTMLFromFile(const FileName: String; const PartParent: TMimePart): TMimepart;
|
2008-04-24 09:59:26 +03:00
|
|
|
var
|
2008-04-24 10:20:39 +03:00
|
|
|
tmp: TStrings;
|
2008-04-24 09:59:26 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
tmp := TStringList.Create;
|
|
|
|
try
|
|
|
|
tmp.LoadFromFile(FileName);
|
|
|
|
Result := AddPartHTML(tmp, PartParent);
|
|
|
|
Finally
|
|
|
|
tmp.Free;
|
2008-04-24 10:05:26 +03:00
|
|
|
end;
|
2008-04-24 09:59:26 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
function TMimeMess.AddPartBinary(const Stream: TStream; const FileName: string; const PartParent: TMimePart): TMimepart;
|
|
|
|
begin
|
|
|
|
Result := AddPart(PartParent);
|
|
|
|
Result.DecodedLines.LoadFromStream(Stream);
|
|
|
|
Result.MimeTypeFromExt(FileName);
|
|
|
|
Result.Description := 'Attached file: ' + FileName;
|
|
|
|
Result.Disposition := 'attachment';
|
|
|
|
Result.FileName := FileName;
|
|
|
|
Result.EncodingCode := ME_BASE64;
|
|
|
|
Result.EncodePart;
|
|
|
|
Result.EncodePartHeader;
|
|
|
|
end;
|
2008-04-24 10:05:26 +03:00
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
function TMimeMess.AddPartBinaryFromFile(const FileName: string; const PartParent: TMimePart): TMimepart;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:20:39 +03:00
|
|
|
tmp: TMemoryStream;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
tmp := TMemoryStream.Create;
|
|
|
|
try
|
|
|
|
tmp.LoadFromFile(FileName);
|
|
|
|
Result := AddPartBinary(tmp, ExtractFileName(FileName), PartParent);
|
|
|
|
finally
|
|
|
|
tmp.Free;
|
2008-04-24 10:05:26 +03:00
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
function TMimeMess.AddPartHTMLBinary(const Stream: TStream; const FileName, Cid: string; const PartParent: TMimePart): TMimepart;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
Result := AddPart(PartParent);
|
|
|
|
Result.DecodedLines.LoadFromStream(Stream);
|
|
|
|
Result.MimeTypeFromExt(FileName);
|
|
|
|
Result.Description := 'Included file: ' + FileName;
|
|
|
|
Result.Disposition := 'inline';
|
|
|
|
Result.ContentID := Cid;
|
|
|
|
Result.FileName := FileName;
|
|
|
|
Result.EncodingCode := ME_BASE64;
|
|
|
|
Result.EncodePart;
|
|
|
|
Result.EncodePartHeader;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
function TMimeMess.AddPartHTMLBinaryFromFile(const FileName, Cid: string; const PartParent: TMimePart): TMimepart;
|
|
|
|
var
|
|
|
|
tmp: TMemoryStream;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
tmp := TMemoryStream.Create;
|
|
|
|
try
|
|
|
|
tmp.LoadFromFile(FileName);
|
|
|
|
Result :=AddPartHTMLBinary(tmp, ExtractFileName(FileName), Cid, PartParent);
|
|
|
|
finally
|
|
|
|
tmp.Free;
|
|
|
|
end;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
2008-04-24 10:05:26 +03:00
|
|
|
|
2008-04-24 10:20:39 +03:00
|
|
|
procedure TMimeMess.EncodeMessage;
|
2008-04-23 23:48:39 +03:00
|
|
|
var
|
2008-04-24 10:05:26 +03:00
|
|
|
l: TStringList;
|
2008-04-24 10:20:39 +03:00
|
|
|
x: integer;
|
2008-04-23 23:48:39 +03:00
|
|
|
begin
|
2008-04-24 10:20:39 +03:00
|
|
|
//merge headers from THeaders and header field from MessagePart
|
2008-04-24 10:05:26 +03:00
|
|
|
l := TStringList.Create;
|
2008-04-23 23:48:39 +03:00
|
|
|
try
|
2008-04-24 10:20:39 +03:00
|
|
|
FHeader.EncodeHeaders(l);
|
|
|
|
x := IndexByBegin('CONTENT-TYPE', FMessagePart.Headers);
|
|
|
|
if x >= 0 then
|
|
|
|
l.add(FMessagePart.Headers[x]);
|
|
|
|
x := IndexByBegin('CONTENT-DESCRIPTION', FMessagePart.Headers);
|
|
|
|
if x >= 0 then
|
|
|
|
l.add(FMessagePart.Headers[x]);
|
|
|
|
x := IndexByBegin('CONTENT-DISPOSITION', FMessagePart.Headers);
|
|
|
|
if x >= 0 then
|
|
|
|
l.add(FMessagePart.Headers[x]);
|
|
|
|
x := IndexByBegin('CONTENT-ID', FMessagePart.Headers);
|
|
|
|
if x >= 0 then
|
|
|
|
l.add(FMessagePart.Headers[x]);
|
|
|
|
x := IndexByBegin('CONTENT-TRANSFER-ENCODING', FMessagePart.Headers);
|
|
|
|
if x >= 0 then
|
|
|
|
l.add(FMessagePart.Headers[x]);
|
|
|
|
FMessagePart.Headers.Assign(l);
|
2008-04-23 23:48:39 +03:00
|
|
|
finally
|
2008-04-24 10:05:26 +03:00
|
|
|
l.Free;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
2008-04-24 10:20:39 +03:00
|
|
|
FMessagePart.ComposeParts;
|
|
|
|
FLines.Assign(FMessagePart.Lines);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
procedure TMimeMess.DecodeMessage;
|
|
|
|
begin
|
|
|
|
FHeader.Clear;
|
|
|
|
FHeader.DecodeHeaders(FLines);
|
|
|
|
FMessagePart.Lines.Assign(FLines);
|
|
|
|
FMessagePart.DecomposeParts;
|
2008-04-23 23:48:39 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|