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

📄 idimap4.pas

📁 Indy控件的使用源代码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      ALength: Integer; ADestFileNameAndPath: string; AEncoding: string): Boolean;
    {CC3: Following added for retrieving the text-only part of a message...}
    function RetrieveText(const AMsgNum: Integer; var AText: string): Boolean;
    {CC4: An alternative for retrieving the text-only part of a message which
    may give a better response from some IMAP implementations...}
    function RetrieveText2(const AMsgNum: Integer; var AText: string): Boolean;
    {CC3: Following added for retrieving the text-only part of a message...}
    function RetrieveTextPeek(const AMsgNum: Integer; var AText: string): Boolean;
    function RetrieveTextPeek2(const AMsgNum: Integer; var AText: string): Boolean;
    //Retrieves only the message header.
    function RetrieveHeader (const AMsgNum: Integer; AMsg: TIdMessage): Boolean;
    //Retrives the current selected mailbox size.
    function RetrieveMailBoxSize: Integer;
    //Returnes the message size.
    function RetrieveMsgSize(const AMsgNum: Integer): Integer;
    //Retrieves a whole message while keeping it's Seen flag untucked    {Do not Localize}
    //(preserving the previous value).
    function RetrievePeek (const AMsgNum: Integer; AMsg: TIdMessage): Boolean;
    //Get the UID corresponding to a relative message number.
    function  GetUID(const AMsgNum: Integer; var AUID: string): Boolean;
    //Copy's a message from the current selected mailbox to the specified mailbox.    {Do not Localize}
    function UIDCopyMsg (const AMsgUID: String; const AMBName: String): Boolean;
    //Checks if the message was read or not.
    function UIDCheckMsgSeen (const AMsgUID: String): Boolean;
    //Marks a message for deletion, it will be deleted when the mailbox will be purged.
    function UIDDeleteMsg(const AMsgUID: String): Boolean;
    //Retrieves all headers of the selected mailbox to the specified TIdMessageCollection.
    {CC5: This is not, and never was, implemented: why would you use it?}
    function UIDRetrieveAllHeaders (AMsgList: TIdMessageCollection): Boolean;
    //Retrieves all envelope and UID of the selected mailbox to the specified TIdMessageCollection.
    function UIDRetrieveAllEnvelopes (AMsgList: TIdMessageCollection): Boolean;
    //Retrieves a whole message while marking it read.
    function UIDRetrieve (const AMsgUID: String; AMsg: TIdMessage): Boolean;
    //Retrieves the message envelope, parses it, and discards the envelope.
    function UIDRetrieveEnvelope (const AMsgUID: String; AMsg: TIdMessage): Boolean;
    //Retrieves the message envelope into a TStringList but does NOT parse it.
    function UIDRetrieveEnvelopeRaw(const AMsgUID: String; ADestList: TStringList): Boolean;
    //Returnes the message flag values.
    {CC: use "var" to get results returned}
    {function UIDRetrieveFlags (const AMsgUID: String; AFlags: TIdMessageFlagsSet): Boolean;}
    function UIDRetrieveFlags (const AMsgUID: String; var AFlags: TIdMessageFlagsSet): Boolean;
    {CC2: Following added for retrieving individual parts of a message...}
    function UIDInternalRetrieveStructure(const AMsgUID: String; AMsg: TIdMessage; AParts: TIdImapMessageParts): Boolean;
    //Retrieve only the message structure (this tells you what parts are in the message).
    function UIDRetrieveStructure(const AMsgUID: String; AMsg: TIdMessage): Boolean; overload;
    function UIDRetrieveStructure(const AMsgUID: String; AParts: TIdImapMessageParts): Boolean; overload;
    {CC2: Following added for retrieving individual parts of a message...}
    {Retrieve a specific individual part of a message}
    function UIDRetrievePart(const AMsgUID: String; const APartNum: Integer;
      var ABuffer: PChar; var ABufferLength: Integer; AEncoding: string = 'text'): Boolean;
    {CC2: Following added for retrieving individual parts of a message...}
    {Retrieve a specific individual part of a message}
    function UIDRetrievePartPeek(const AMsgUID: String; const APartNum: Integer;
      var ABuffer: PChar; var ABufferLength: Integer; AEncoding: string = 'text'): Boolean;
    {CC2: Following added for retrieving individual parts of a message...}
    {Retrieve a specific individual part of a message}
    function UIDRetrievePartToFile(const AMsgUID: String; const APartNum: Integer;
      ALength: Integer; ADestFileNameAndPath: string; AEncoding: string): Boolean;
    {CC2: Following added for retrieving individual parts of a message...}
    {Retrieve a specific individual part of a message}
    function UIDRetrievePartToFilePeek(const AMsgUID: String; const APartNum: Integer;
      ALength: Integer; ADestFileNameAndPath: string; AEncoding: string): Boolean;
    {CC3: Following added for retrieving the text-only part of a message...}
    function UIDRetrieveText(const AMsgUID: String; var AText: string): Boolean;
    function UIDRetrieveText2(const AMsgUID: String; var AText: string): Boolean;
    {CC3: Following added for retrieving the text-only part of a message...}
    function UIDRetrieveTextPeek(const AMsgUID: String; var AText: string): Boolean;
    function UIDRetrieveTextPeek2(const AMsgUID: String; var AText: string): Boolean;
    //Retrieves only the message header.
    function UIDRetrieveHeader (const AMsgUID: String; AMsg: TIdMessage): Boolean;
    //Retrives the current selected mailbox size.
    function UIDRetrieveMailBoxSize: Integer;
    //Returnes the message size.
    function UIDRetrieveMsgSize(const AMsgUID: String): Integer;
    //Retrieves a whole message while keeping it's Seen flag untucked    {Do not Localize}
    //(preserving the previous value).
    function UIDRetrievePeek (const AMsgUID: String; AMsg: TIdMessage): Boolean;
    //Searches the current selected mailbox for messages matching the SearchRec and
    //returnes the results as UIDs to the mailbox SearchResults array.
    function  UIDSearchMailBox (const ASearchInfo: array of TIdIMAP4SearchRec{Array}): Boolean;//array of TIdIMAP4SearchRec ) : Boolean;
    //Changes (adds or removes) message flags.
    function UIDStoreFlags (const AMsgUID: String;
      const AStoreMethod: TIdIMAP4StoreDataItem;
      const AFlags: TIdMessageFlagsSet): Boolean;
    //Removes the specified mailbox name from the server's set of "active" or "subscribed"    {Do not Localize}
    //mailboxes as returned by the LSUB command.
    function UnsubscribeMailBox (const AMBName: String): Boolean;
  { TIdIMAP4 Commands }
  { IdTCPConnection Commands }
{$IFDEF INDY100}
    procedure GetInternalResponse (const ATag: String); reintroduce; overload;
    procedure GetInternalResponse; overload; override;
{$ELSE}
    procedure GetInternalResponse (const ATag: String); overload;
    procedure GetInternalResponse; overload;
{$ENDIF}
    procedure GetInternalLineResponse (const ATag: String);
    function GetResponse(const ATag: String; const
      AAllowedResponses: array of SmallInt): SmallInt; reintroduce; overload;
    function GetResponse(const AAllowedResponses: array of SmallInt):
      SmallInt; reintroduce; overload;
    function GetLineResponse(const ATag: String;
      const AAllowedResponses: array of SmallInt): SmallInt;
{$IFDEF INDY100}
    function SendCmd(const AOut: string; const AResponse: Array of SmallInt): SmallInt; overload; override;
    function SendCmd(const ATag, AOut: string; const AResponse: SmallInt = -1): SmallInt; reintroduce; overload;
    function SendCmd(const ATag, AOut: string; const AResponse: array of SmallInt):
      SmallInt; reintroduce; overload;
{$ELSE}
    function SendCmd(const ATag, AOut: string; const AResponse: SmallInt = -1): SmallInt; overload;
    function SendCmd(const ATag, AOut: string; const AResponse: array of SmallInt):
      SmallInt; overload;
{$ENDIF}
    function  ReadLnWait: string;
{$IFDEF INDY100}
    procedure WriteLn(AOut: string);
{$ELSE}
    procedure WriteLn(AOut: string); reintroduce;
{$ENDIF}
  { IdTCPConnection Commands }
  published
    property OnAlert: TIdAlertEvent read FOnAlert write FOnAlert;
    property Password;
    property RetrieveOnSelect: TIdRetrieveOnSelect read FRetrieveOnSelect write FRetrieveOnSelect default rsDisabled;
    property Port default IdPORT_IMAP4;
    property Username;
    property MailBoxSeparator: Char read FMailBoxSeparator write FMailBoxSeparator default '/';    {Do not Localize}
{$IFDEF INDY100}
    property Host;
    property UseTLS;
    property AuthenticationType default DEF_IMAP4_AUTH;
{$ENDIF}
  end;

implementation

uses
  IdEMailAddress,
  IdException,
  IdResourceStrings,
{$IFDEF INDY100}
  IdSASLList,
  IdExplicitTLSClientServerBase,
  IdAttachmentMemory,
  IdReplyIMAP4,  {CC6: for Indy 10 changes}
{$ENDIF}
  IdTCPConnection;

type
  TIdIMAP4FetchDataItem =
  ( fdAll,           //Macro equivalent to: (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE)
    fdBody,          //Non-extensible form of BODYSTRUCTURE.
    fdBodyExtensible,
    fdBodyPeek,
    fdBodyStructure, //The [MIME-IMB] body structure of the message.  This
                     //is computed by the server by parsing the [MIME-IMB]
                     //header fields in the [RFC-822] header and [MIME-IMB] headers.
    fdEnvelope,      //The envelope structure of the message.  This is
                     //computed by the server by parsing the [RFC-822]
                     //header into the component parts, defaulting various
                     //fields as necessary.
    fdFast,          //Macro equivalent to: (FLAGS INTERNALDATE RFC822.SIZE)
    fdFlags,         //The flags that are set for this message.
    fdFull,          //Macro equivalent to: (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY)
    fdInternalDate,  //The internal date of the message.
    fdRFC822,        //Functionally equivalent to BODY[], differing in the
                     //syntax of the resulting untagged FETCH data (RFC822
                     //is returned).
    fdRFC822Header,  //Functionally equivalent to BODY.PEEK[HEADER],
                     //differing in the syntax of the resulting untagged
                     //FETCH data (RFC822.HEADER is returned).
    fdRFC822Size,    //The [RFC-822] size of the message.
    fdRFC822Text,    //Functionally equivalent to BODY[TEXT], differing in
                     //the syntax of the resulting untagged FETCH data
                     //(RFC822.TEXT is returned).
    fdUID );         //The unique identifier for the message.

const
   IMAP4Commands : array [cmdCapability..cmdXCmd] of String =
   ( { Client Commands - Any State}
    'CAPABILITY', {Do not Localize}
    'NOOP', {Do not Localize}
    'LOGOUT', {Do not Localize}
    { Client Commands - Non Authenticated State}
    'AUTHENTICATE', {Do not Localize}
    'LOGIN', {Do not Localize}
    { Client Commands - Authenticated State}
    'SELECT', {Do not Localize}
    'EXAMINE', {Do not Localize}
    'CREATE', {Do not Localize}
    'DELETE', {Do not Localize}
    'RENAME', {Do not Localize}
    'SUBSCRIBE', {Do not Localize}
    'UNSUBSCRIBE', {Do not Localize}
    'LIST', {Do not Localize}
    'LSUB', {Do not Localize}
    'STATUS', {Do not Localize}
    'APPEND', {Do not Localize}
    { Client Commands - Selected State}
    'CHECK', {Do not Localize}
    'CLOSE', {Do not Localize}
    'EXPUNGE', {Do not Localize}
    'SEARCH', {Do not Localize}
    'FETCH', {Do not Localize}
    'STORE', {Do not Localize}
    'COPY', {Do not Localize}
    'UID', {Do not Localize}
    { Client Commands - Experimental/ Expansion}
    'X' ); {Do not Localize}

   IMAP4FetchDataItem : array [fdAll..fdUID] of String =
   ( 'ALL', {Do not Localize}          //Macro equivalent to: (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE)
     'BODY', {Do not Localize}         //Non-extensible form of BODYSTRUCTURE.
     'BODY[%s]<%s>', {Do not Localize}
     'BODY.PEEK[]', {Do not Localize}
     'BODYSTRUCTURE', {Do not Localize}//The [MIME-IMB] body structure of the message.  This
                                       //is computed by the server by parsing the [MIME-IMB]
                                       //header fields in the [RFC-822] header and [MIME-IMB] headers.
     'ENVELOPE', {Do not Localize}     //The envelope structure of the message.  This is
                                       //computed by the server by parsing the [RFC-822]
                                       //header into the component parts, defaulting various
                                       //fields as necessary.
     'FAST', {Do not Localize}         //Macro equivalent to: (FLAGS INTERNALDATE RFC822.SIZE)
     'FLAGS', {Do not Localize}        //The flags that are set for this message.
     'FULL', {Do not Localize}         //Macro equivalent to: (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY)
     'INTERNALDATE', {Do not Localize} //The internal date of the message.
     'RFC822', {Do not Localize}       //Functionally equivalent to BODY[], differing in the
                                       //syntax of the resulting untagged FETCH data (RFC822
                                       //is returned).
     'RFC822.HEADER', {Do not Localize}//Functionally equivalent to BODY.PEEK[HEADER],
                                       //differing in the syntax of the resulting untagged
                                       //FETCH data (RFC822.HEADER is returned).
     'RFC822.SIZE', {Do not Localize}  //The [RFC-822] size of the message.
     'RFC822.TEXT', {Do not Localize}  //Functionally equivalent to BODY[TEXT], differing in
                                       //the syntax of the resulting untagged FETCH data
                                       //(RFC822.TEXT is returned).
     'UID' ); {Do not Localize}        //The unique identifier for the message.


   IMAP4SearchKeys : array [skAll..skUnseen] of String =
   ( 'ALL', {Do not Localize}      //All messages in the mailbox; the default initial key for ANDing.
     'ANSWERED', {Do not Localize} //Messages with the \Answered flag set.
     'BCC', {Do not Localize}      //Messages that contain the specified string in the envelope structure's BCC field.
     'BEFORE', {Do not Localize}   //Messages whose internal date is earlier than the specified date.
     'BODY', {Do not Localize}     //Messages that contain the specified string in the body of the message.
     'CC', {Do not Localize}       //Messages that contain the specified string in the envelope structure's CC field.
     'DELETED', {Do not Localize}  //Messages with the \Deleted flag set.
     'DRAFT', {Do not Localize}    //Messages with the \Draft flag set.
     'FLAGGED', {Do not Localize}  //Messages with the \Flagged flag set.
     'FROM', {Do not Localize}     //Messages that contain the specified string in the envelope structure's FROM field.
     'HEADER', {Do not Localize}   //Messages that have a header with the specified field-name (as defined in [RFC-822])
                                   //and that contains the specified string in the [RFC-822] field-body.
     'KEYWORD', {Do not Localize}  //Messages with the specified keyword set.
     'LARGER', {Do not Localize}   //Messages with an [RFC-822] size larger than the specified number of octets.
     'NEW', {Do not Localize}      //Messages that have the \Recent flag set but not the \Seen flag.
                                   //This is functionally equivalent to "(RECENT UNSEEN)".
     'NOT', {Do not Localize}      //Messages that do not match the specified search key.
     'OLD', {Do not Localize}      //Messages that do not have the \Recent flag set. This is functionally
                                   //equivalent to "NOT RECENT" (as opposed to "NOT NEW").
     'ON', {Do not Localize}       //Messages whose internal date is within the specified date.
     'OR', {Do not Localize}       //Messages that match either search key.
     'RECENT', {Do not Localize}   //Messages that have the \Recent flag set.
     'SEEN', {Do not Localize}     //Messages that have the \Seen flag set.
     'SENTBEFORE',{Do not Localize}//Messages whose [RFC-822] Date: header is earlier than the specified date.
     'SENTON', {Do not Localize}   //Messages whose [RFC-822] Date: header is within the specified date.
     'SENTSINCE', {Do not Localize}//Messages whose [RFC-822] Date: header is within or later than the specified date.
     'SINCE', {Do not Localize}    //Messages whose internal date is within or later than the specified date.
     'SMALLER', {Do not Localize}  //Messages with an [RFC-822] size smaller than the specified number of octets.
     'SUBJECT', {Do not Localize}  //Messages that contain the specified string in the envelope structure's SUBJECT field.
     'TEXT', {Do not Localize}     //Messages that contain the specified string in the header or body of the message.
     'TO', {Do not Localize}       //Messages that contain the specified string in the envelope structure's TO field.
     'UID', {Do not Localize}      //Messages with unique identifiers corresponding to the specified unique identifier set.
     'UNANSWERED',{Do not Localize}//Messages that do not have the \Answered flag set.
     'UNDELETED', {Do not Localize}//Messages that do not have the \Deleted flag set.
     'UNDRAFT', {Do not Localize}  //Messages that do not have the \Draft flag set.
     'UNFLAGGED', {Do not Localize}//Messages that do not have the \Flagged flag set.
     'UNKEYWORD', {Do not Localize}//Messages that do not have the specified keyword set.
     'UNSEEN' ); {Do not Localize}

   IMAP4StoreDataItem : array [sdReplace..sdRemoveSilent] of String =
   ( 'FLAGS', {Do not Localize}
     'FLAGS.SILENT', {Do not Localize}
     '+FLAGS', {Do not Localize}
     '+FLAGS.SILENT', {Do not Localize}
     '-FLAGS', {Do not Localize}
     '-FLAGS.SILENT' ); {Do not Localize}

⌨️ 快捷键说明

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