⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idmessage.pas

📁 photo.163.com 相册下载器 多线程下载
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{ $HDR$}
{**********************************************************************}
{ Unit archived using Team Coherence                                   }
{ Team Coherence is Copyright 2002 by Quality Software Components      }
{                                                                      }
{ For further information / comments, visit our WEB site at            }
{ http://www.TeamCoherence.com                                         }
{**********************************************************************}
{}
{ $Log:  11667: IdMessage.pas
{
{   Rev 1.51    10/26/2004 10:25:44 PM  JPMugaas
{ Updated refs.
}
{
{   Rev 1.50    2004.10.26 9:10:00 PM  czhower
{ TIdStrings
}
{
{   Rev 1.49    24.08.2004 18:01:44  Andreas Hausladen
{ Added AttachmentBlocked property to TIdAttachmentFile.
}
{
{   Rev 1.48    6/29/04 12:29:04 PM  RLebeau
{ Updated TIdMIMEBoundary.FindBoundary() to check the string length after
{ calling Trim() before referencing the string data
}
{
{   Rev 1.47    6/9/04 5:38:48 PM  RLebeau
{ Updated ClearHeader() to clear the MsgId and UID properties.
{ 
{ Updated SetUseNowForDate() to support AValue being set to False
}
{
{   Rev 1.46    16/05/2004 18:54:42  CCostelloe
{ New TIdText/TIdAttachment processing
}
{
{   Rev 1.45    03/05/2004 20:43:08  CCostelloe
{ Fixed bug where QP or base64 encoded text part got header encoding
{ incorrectly outputted as 8bit.
}
{
{   Rev 1.44    4/25/04 1:29:34 PM  RLebeau
{ Bug fix for SaveToStream
}
{
{   Rev 1.42    23/04/2004 20:42:18  CCostelloe
{ Bug fixes plus support for From containing multiple addresses
}
{
{   Rev 1.41    2004.04.18 1:39:20 PM  czhower
{ Bug fix for .NET with attachments, and several other issues found along the
{ way.
}
{
{   Rev 1.40    2004.04.16 11:30:56 PM  czhower
{ Size fix to IdBuffer, optimizations, and memory leaks
}
{
{   Rev 1.39    14/03/2004 17:47:54  CCostelloe
{ Bug fix: quoted-printable attachment encoding was changed to base64.
}
{
{   Rev 1.38    2004.02.03 5:44:00 PM  czhower
{ Name changes
}
{
{   Rev 1.37    2004.02.03 2:12:14 PM  czhower
{ $I path change
}
{
{   Rev 1.36    26/01/2004 01:51:14  CCostelloe
{ Changed implementation of supressing BCC List generation
}
{
{   Rev 1.35    25/01/2004 21:15:42  CCostelloe
{ Added SuppressBCCListInHeader property for use by TIdSMTP
}
{
{   Rev 1.34    1/21/2004 1:17:14 PM  JPMugaas
{ InitComponent
}
{
{   Rev 1.33    1/19/04 11:36:02 AM  RLebeau
{ Updated GenerateHeader() to remove support for the BBCList property
}
{
{   Rev 1.32    16/01/2004 17:30:18  CCostelloe
{ Added support for BinHex4.0 encoding
}
{
{   Rev 1.31    11/01/2004 19:53:20  CCostelloe
{ Revisions for TIdMessage SaveToFile & LoadFromFile for D7 & D8
}
{
{   Rev 1.29    08/01/2004 23:43:40  CCostelloe
{ LoadFromFile/SaveToFile now work in D7 again
}
{
{   Rev 1.28    1/7/04 11:07:16 PM  RLebeau
{ Bug fix for various TIdMessage properties that were not previously using
{ setter methods correctly.
}
{
{   Rev 1.27    08/01/2004 00:30:26  CCostelloe
{ Start of reimplementing LoadFrom/SaveToFile
}
{
{   Rev 1.26    21/10/2003 23:04:32  CCostelloe
{ Bug fix: removed AttachmentEncoding := '' in SetEncoding.
}
{
{   Rev 1.25    21/10/2003 00:33:04  CCostelloe
{ meMIME changed to meDefault in TIdMessage.Create
}
{
{   Rev 1.24    10/17/2003 7:42:54 PM  BGooijen
{ Changed default Encoding to MIME
}
{
    Rev 1.23    10/17/2003 12:14:08 AM  DSiders
  Added localization comments.
}
{
{   Rev 1.22    2003.10.14 9:57:04 PM  czhower
{ Compile todos
}
{
{   Rev 1.21    10/12/2003 1:55:46 PM  BGooijen
{ Removed IdStrings from uses
}
{
{   Rev 1.20    2003.10.11 10:01:26 PM  czhower
{ .inc path
}
{
{   Rev 1.19    10/10/2003 10:42:26 PM  BGooijen
{ DotNet
}
{
{   Rev 1.18    9/10/2003 1:50:54 PM  SGrobety
{ DotNet
}
{
{   Rev 1.17    10/8/2003 9:53:12 PM  GGrieve
{ use IdCharsets
}
{
{   Rev 1.16    05/10/2003 16:38:50  CCostelloe
{ Restructured MIME boundary output
}
{
{   Rev 1.15    2003.10.02 9:27:50 PM  czhower
{ DotNet Excludes
}
{
{   Rev 1.14    01/10/2003 17:58:52  HHariri
{ More fixes for Multipart Messages and also fixes for incorrect transfer
{ encoding settings
}
{
{   Rev 1.12    9/28/03 1:36:04 PM  RLebeau
{ Updated GenerateHeader() to support the BBCList property
}
{
{   Rev 1.11    26/09/2003 00:29:34  CCostelloe
{ IdMessage.Encoding now set when email decoded; XXencoded emails now decoded;
{ logic added to GenerateHeader
}
{
{   Rev 1.10    04/09/2003 20:42:04  CCostelloe
{ GenerateHeader sets From's Name field to Address field if Name blank;
{ trailing spaces removed after boundary in FindBoundary; force generation of
{ InReplyTo header.
}
{
{   Rev 1.9    29/07/2003 01:14:30  CCostelloe
{ In-Reply-To fixed in GenerateHeader
}
{
{   Rev 1.8    11/07/2003 01:11:02  CCostelloe
{ GenerateHeader changed from function to procedure, results now put in
{ LastGeneratedHeaders.  Better for user (can see headers sent) and code still
{ efficient.
}
{
{   Rev 1.7    10/07/2003 22:39:00  CCostelloe
{ Added LastGeneratedHeaders field and modified GenerateHeaders so that a copy
{ of the last set of headers generated for this message is maintained (see
{ comments starting "CC")
}
{
{   Rev 1.6    2003.06.23 9:46:54 AM  czhower
{ Russian, Ukranian support for headers.
}
{
{   Rev 1.5    6/3/2003 10:46:54 PM  JPMugaas
{ In-Reply-To header now supported.
}
{
    Rev 1.4    1/27/2003 10:07:46 PM  DSiders
  Corrected error setting file stream permissions in LoadFromFile.  Bug Report
  649502.
}
{
{   Rev 1.3    27/1/2003 3:07:10 PM  SGrobety
{ X-Priority header only added if priority <> mpNormal (because of spam filters)
}
{
{   Rev 1.2    09/12/2002 18:19:00  ANeillans    Version: 1.2
{ Removed X-Library Line that was causing people problems with spam detection
{ software , etc.
}
{
{   Rev 1.1    12/5/2002 02:53:56 PM  JPMugaas
{ Updated for new API definitions.
}
{
{   Rev 1.0    11/13/2002 07:56:52 AM  JPMugaas
}
{//////////////////////////////////////////////////////////////////
2001-Jul-11 Hadi Hariri
  TODO: Make checks for encoding and content-type later on.
  TODO: Add TIdHTML, TIdRelated
  TODO: CountParts on the fly
  TODO: Merge Encoding and AttachmentEncoding
  TODO: Make encoding plugable
  TODO: Clean up ISO header coding
/////////////////////////////////////////////////////////////////}

unit IdMessage;

{
2004-05-04 Ciaran Costelloe
  - Replaced meUU with mePlainText.  This also meant that UUE/XXE encoding was pushed
    down from the message-level to the MessagePart level, where it belongs.
2004-04-20 Ciaran Costelloe
  - Added support for multiple From addresses (per RFC 2822, section 3.6.2) by
    adding a FromList field.  The previous From field now maps to FromList[0].
2003-10-04 Ciaran Costelloe (see comments starting CC4)
2003-09-20 Ciaran Costelloe (see comments starting CC2)
  - Added meDefault, meXX to TIdMessageEncoding.
    Code now sets TIdMessage.Encoding when it decodes an email.
    Modified TIdMIMEBoundary to work as a straight stack, now Push/Pops ParentPart also.
    Added meDefault, meXX to TIdMessageEncoding.
    Moved logic from SendBody to GenerateHeader, added extra logic to avoid exceptions:
      Change any encodings we dont know to base64
      We dont support attachments in an encoded body, change it to a supported combination
    Made changes to support ConvertPreamble and MIME message bodies with a
      ContentTransferEncoding of base64, quoted-printable.
    ProcessHeaders now decodes BCC list.
2003-09-02 Ciaran Costelloe
  - Added fix to FindBoundary suggested by Juergen Haible to remove trailing space
    after boundary added by some clients.
2003-07-10 Ciaran Costelloe
  - Added LastGeneratedHeaders property, see comments starting CC.  Changed
    GenerateHeader from function to procedure, it now puts the generated headers
    into LastGeneratedHeaders, which is where dependant units should take the
    results from.  This ensures that the headers that were generated are
    recorded, which some users' programs may need.
2002-12-09 Andrew Neillans
  - Removed X-Library line
2002-08-30 Andrew P.Rybin
  - now InitializeISO is IdMessage method
2001-12-27 Andrew P.Rybin
  Custom InitializeISO, ExtractCharSet
2001-Oct-29 Don Siders
  Added EIdMessageCannotLoad exception.
  Added RSIdMessageCannotLoad constant.
  Added TIdMessage.LoadFromStream.
  Modified TIdMessage.LoadFromFile to call LoadFromStream.
  Added TIdMessage.SaveToStream.
  Modified TIdMessage.SaveToFile to call SaveToStream.
  Modified TIdMessage.GenerateHeader to include headers received but not used in properties.
2001-Sep-14 Andrew Neillans
  Added LoadFromFile Header only
2001-Sep-12 Johannes Berg
  Fixed upper/lowercase in uses clause for Kylix
2001-Aug-09 Allen O'Neill
  Added line to check for valid charset value before adding second ';' after content-type boundry
2001-Aug-07 Allen O'Neill
  Added SaveToFile & LoadFromFile ... Doychin fixed
2001-Jul-11 Hadi Hariri
  Added Encoding for both MIME and UU.
2000-Jul-25 Hadi Hariri
 - Added support for MBCS
2000-Jun-10 Pete Mee
 - Fixed some minor but annoying bugs.
2000-May-06 Pete Mee
 - Added coder support directly into TIdMessage.
}

{ TODO : Moved Decode/Encode out and will add later,. Maybe TIdMessageEncode, Decode?? }

{ TODO : Support any header in TMessagePart }

{ DESIGN NOTE: The TIdMessage has an fBody which should only ever be the
    raw message.  TIdMessage.fBody is only raw if TIdMessage.fIsEncoded = true

    The component parts are thus possibly made up of the following
    order of TMessagePart entries:

    MP[0] : Possible prologue text (fBoundary is '')

    MP[0 or 1 - depending on prologue existence] :
      fBoundary = boundary parameter from Content-Type

    MP[next...] : various parts with or without fBoundary = ''

    MP[MP.Count - 1] : Possible epilogue text (fBoundary is '')
    }

{ DESIGN NOTE: If TMessagePart.fIsEncoded = True, then TMessagePart.fBody
    is the encoded raw message part.  Otherwise, it is the (decoded) text.
    }

interface

{$I IdCompilerDefines.inc}

uses
  Classes,
  IdTStrings,
  IdBaseComponent, IdExceptionCore, IdEMailAddress, IdHeaderList,
  IdCoderHeader, SysUtils, IdMessageParts, IdAttachment;

type
  TIdMessagePriority = (mpHighest, mpHigh, mpNormal, mpLow, mpLowest);

const
  ID_MSG_NODECODE = False;
  ID_MSG_USENOWFORDATE = True;
  ID_MSG_PRIORITY = mpNormal;

type
  TIdMIMEBoundary = class(TObject)
  protected
    FBoundaryList: TIdStrings;
    {CC: Added ParentPart as a TIdStrings so I dont have to create a TIntegers}
    FParentPartList: TIdStrings;
    function GetBoundary: string;
    function GetParentPart: integer;
  public
    constructor Create;
    destructor Destroy; override;
    class function FindBoundary(AContentType: string): string;
    procedure Push(ABoundary: string; AParentPart: integer);
    procedure Pop;
    procedure Clear;
    function Count: integer;

    property Boundary: string read GetBoundary;
    property ParentPart: integer read GetParentPart;
  end;

  TIdMessageFlags =
  ( mfAnswered, //Message has been answered.
    mfFlagged, //Message is "flagged" for urgent/special attention.
    mfDeleted, //Message is "deleted" for removal by later EXPUNGE.
    mfDraft, //Message has not completed composition (marked as a draft).
    mfSeen, //Message has been read.
    mfRecent ); //Message is "recently" arrived in this mailbox.

  TIdMessageFlagsSet = set of TIdMessageFlags;

  {WARNING: Replaced meUU with mePlainText in Indy 10 due to meUU being misleading.
  This is the MESSAGE-LEVEL "encoding", really the format or layout of the message.
  When encoding, the user can let Indy decide on the encoding by
  leaving it at meDefault, or he can pick meMIME or mePlainText}
  //TIdMessageEncoding = (meDefault, meMIME, meUU, meXX);
  TIdMessageEncoding = (meDefault, meMIME, mePlainText);

  TIdInitializeIsoEvent = procedure (var VTransferHeader: TTransfer; var VHeaderEncoding: Char;
    var VCharSet: string) of object;

  TIdMessage = class;

  TIdCreateAttachmentEvent = procedure(const AMsg: TIdMessage;
   const AHeaders: TIdStrings;
   var AAttachment: TIdAttachment) of object;

  TIdMessage = class(TIdBaseComponent)
  protected
    FBccList: TIdEmailAddressList;
    FBody: TIdStrings;
    FCharSet: string;
    FCcList: TIdEmailAddressList;
    FContentType: string;
    FContentTransferEncoding: string;
    FContentDisposition: string;
    FDate: TDateTime;
    FIsEncoded : Boolean;
    FExtraHeaders: TIdHeaderList;
    FEncoding: TIdMessageEncoding;
    FFlags: TIdMessageFlagsSet;
    FFromList: TIdEmailAddressList;
    FHeaders: TIdHeaderList;
    FMessageParts: TIdMessageParts;
    FMIMEBoundary: TIdMIMEBoundary;
    FMsgId: string;
    FNewsGroups: TIdStrings;
    FNoEncode: Boolean;
    FNoDecode: Boolean;
    FOnInitializeISO: TIdInitializeISOEvent;
    FOrganization: string;
    FPriority: TIdMessagePriority;
    FSubject: string;
    FReceiptRecipient: TIdEmailAddressItem;
    FRecipients: TIdEmailAddressList;
    FReferences: string;
    FInReplyTo : String;
    FReplyTo: TIdEmailAddressList;
    FSender: TIdEMailAddressItem;
    FUID: String;
    FXProgram: string;
    FOnCreateAttachment: TIdCreateAttachmentEvent;
    FLastGeneratedHeaders: TIdHeaderList;
    FConvertPreamble: Boolean;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -