📄 idimap4.pas
字号:
{CC3: Following added for TLS support..}
function IsCapabilityListed(ACapability: string):Boolean;
{CC6: Added to support RetrieveEnvelopeRaw...}
function InternalRetrieveEnvelope(const AMsgNum: Integer; AMsg: TIdMessage; ADestList: TStringList): Boolean;
{CC6: Added to support UIDRetrieveEnvelopeRaw...}
function UIDInternalRetrieveEnvelope(const AMsgUID: String; AMsg: TIdMessage; ADestList: TStringList): Boolean;
{CC3: Need to validate message numbers (relative and UIDs), because otherwise
the routines wait for a response that never arrives and so functions never return.
Also used for validating part numbers.}
function IsNumberValid(const ANumber: Integer): Boolean;
function IsUIDValid(const AUID: string): Boolean;
{CC6: Override IdMessageClient's ReceiveBody due to the responses from some
servers...}
procedure ReceiveBody(AMsg: TIdMessage; const ADelim: string = '.'); override; {Do not Localize}
public
{ TIdIMAP4 Commands }
//Requests a listing of capabilities that the server supports.
function Capability (ASlCapability: TStrings): Boolean;
procedure DoAlert (const AMsg: String);
property ConnectionState: TIdIMAP4ConnectionState read FConnectionState;
property MailBox: TIdMailBox read FMailBox write SetMailBox;
{CC7: Two versions of AppendMsg are provided. The first is the normal one you
would use. The second allows you to specify an alternative header list which
will be used in place of AMsg.Headers.
An email client may need the second type if it sends an email via IdSMTP and wants
to copy it to a "Sent" IMAP folder. In Indy 9, IdSMTP internally generates and
transmits the headers but does not keep them, so what you may need to do is to
subclass IdSMTP, override SendHeader so that the TIdHeaderList is returned (and
also override both SendMsg and Send to get it back to you), then use the
second version of AppendMsg to use the returned TIdHeaderList. In Indy 10,
IdSMTP puts the generated headers in the LastGeneratedHeaders field, so you
can use the second version of AppendMsg, passing it AMsg.LastGeneratedHeaders as
the AAlternativeHeaders field. Note that IdSMTP puts both the Headers and
the ExtraHeaders fields in LastGeneratedHeaders.}
function AppendMsg (const AMBName: String; AMsg: TIdMessage; const AFlags: TIdMessageFlagsSet = []): Boolean; overload;
function AppendMsg (const AMBName: String; AMsg: TIdMessage; AAlternativeHeaders: TIdHeaderList; const AFlags: TIdMessageFlagsSet = []): Boolean; overload;
//Requests a checkpoint of the currently selected mailbox. Does NOTHING on most servers.
function CheckMailBox: Boolean;
//Checks if the message was read or not.
function CheckMsgSeen (const AMsgNum: Integer): Boolean;
//Connects and logins to the IMAP4 account.
procedure Connect(const ATimeout: Integer = IdTimeoutDefault); override;
//Closes the current selected mailbox in the account. {Do not Localize}
function CloseMailBox: Boolean;
constructor Create(AOwner: TComponent); override;
//Creates a new mailbox with the specified name in the account. {Do not Localize}
function CreateMailBox (const AMBName: String): Boolean;
//Deletes the specified mailbox from the account. {Do not Localize}
function DeleteMailBox (const AMBName: String): Boolean;
//Marks a message for deletion, it will be deleted when the mailbox will be purged.
function DeleteMsgs(const AMsgNumList: array of Integer): Boolean;
destructor Destroy; override;
//Logouts and disconnects from the IMAP account.
procedure Disconnect; override;
//Examines the specified mailbox and inserts the results to the TIdMailBox provided. {Do not Localize}
function ExamineMailBox (const AMBName: String; AMB: TIdMailBox): Boolean;
//Expunges (deletes the marked files) the current selected mailbox in the account. {Do not Localize}
function ExpungeMailBox: Boolean;
//Sends a NOOP (No Operation) to keep the account connection with the server alive.
procedure KeepAlive;
//Returns a list of all the child mailboxes (one level down) to the mailbox supplied.
//This should be used when you fear that there are to many mailboxes and the listing of
//all of them could be time consuming, so this should be used to retrieve specific mailboxes.
function ListInferiorMailBoxes (AMailBoxList, AInferiorMailBoxList: TStringList): Boolean;
//Returns a list of all the mailboxes in the user account.
function ListMailBoxes (AMailBoxList: TStringList): Boolean;
//Returns a list of all the subscribed mailboxes in the user account.
function ListSubscribedMailBoxes (AMailBoxList: TStringList): Boolean;
//Renames the specified mailbox in the account. {Do not Localize}
function RenameMailBox (const AOldMBName, ANewMBName: String): Boolean;
//Searches the current selected mailbox for messages matching the SearchRec and
//returnes the results to the mailbox SearchResults array.
function SearchMailBox (const ASearchInfo: array of TIdIMAP4SearchRec{Array}): Boolean;//array of TIdIMAP4SearchRec ) : Boolean;
//Selects the current a mailbox in the account. {Do not Localize}
function SelectMailBox (const AMBName: String): Boolean;
//Retrieves the status of the indicated mailbox.
{CC2: It is pointless calling StatusMailBox with AStatusDataItems set to []
because you are asking the IMAP server to update none of the status flags.
Instead, if called with no AStatusDataItems specified, use the standard flags
returned by SelectMailBox, which allows the user to easily check if the mailbox
has changed. Overload the functions, since AStatusDataItems cannot be set
to nil.}
function StatusMailBox (const AMBName: String; AMB: TIdMailBox): Boolean; overload;
function StatusMailBox (const AMBName: String; AMB: TIdMailBox; const AStatusDataItems: array of TIdIMAP4StatusDataItem): Boolean; overload;
//Changes (adds or removes) message flags.
function StoreFlags (const AMsgNumList: array of Integer;
const AStoreMethod: TIdIMAP4StoreDataItem; const AFlags: TIdMessageFlagsSet): Boolean;
//Adds the specified mailbox name to the server's set of "active" or "subscribed" {Do not Localize}
//mailboxes as returned by the LSUB command.
function SubscribeMailBox (const AMBName: String): Boolean;
{CC8: Added CopyMsg, should have always been there...}
function CopyMsg (const AMsgNum: Integer; const AMBName: String): Boolean;
//Copies a message from the current selected mailbox to the specified mailbox. {Do not Localize}
function CopyMsgs (const AMsgNumList: array of Integer; const AMBName: String): Boolean;
//Retrieves a whole message while marking it read.
function Retrieve (const AMsgNum: Integer; AMsg: TIdMessage): Boolean;
//Retrieves all envelope of the selected mailbox to the specified TIdMessageCollection.
function RetrieveAllEnvelopes (AMsgList: TIdMessageCollection): Boolean;
//Retrieves all headers of the selected mailbox to the specified TIdMessageCollection.
function RetrieveAllHeaders (AMsgList: TIdMessageCollection): Boolean;
//Retrieves all messages of the selected mailbox to the specified TIdMessageCollection.
function RetrieveAllMsgs (AMsgList: TIdMessageCollection): Boolean;
//Retrieves the message envelope, parses it, and discards the envelope.
function RetrieveEnvelope (const AMsgNum: Integer; AMsg: TIdMessage): Boolean;
//Retrieves the message envelope into a TStringList but does NOT parse it.
function RetrieveEnvelopeRaw(const AMsgNum: Integer; ADestList: TStringList): Boolean;
//Returnes the message flag values.
{CC: use "var" to get results returned}
{function RetrieveFlags (const AMsgNum: Integer; AFlags: TIdMessageFlagsSet): Boolean;}
function RetrieveFlags (const AMsgNum: Integer; var AFlags: TIdMessageFlagsSet): Boolean;
{CC2: Following added for retrieving individual parts of a message...}
function InternalRetrieveStructure(const AMsgNum: Integer; AMsg: TIdMessage; AParts: TIdImapMessageParts): Boolean;
//Retrieve only the message structure (this tells you what parts are in the message).
function RetrieveStructure(const AMsgNum: Integer; AMsg: TIdMessage): Boolean; overload;
function RetrieveStructure(const AMsgNum: Integer; AParts: TIdImapMessageParts): Boolean; overload;
{CC2: Following added for retrieving individual parts of a message...}
{Retrieve a specific individual part of a message}
function RetrievePart(const AMsgNum: Integer; const APartNum: Integer;
var ABuffer: PChar; var ABufferLength: Integer; AEncoding: string = 'text'): Boolean; {Do not Localize}
{CC2: Following added for retrieving individual parts of a message...}
{Retrieve a specific individual part of a message}
function RetrievePartPeek(const AMsgNum: Integer; const APartNum: Integer;
var ABuffer: PChar; var ABufferLength: Integer; AEncoding: string = 'text'): Boolean; {Do not Localize}
{CC2: Following added for retrieving individual parts of a message...}
{Retrieve a specific individual part of a message}
function RetrievePartToFile(const AMsgNum: Integer; 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 RetrievePartToFilePeek(const AMsgNum: Integer; const APartNum: Integer;
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 its 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;
//Copies a message from the current selected mailbox to the specified mailbox. {Do not Localize}
function UIDCopyMsg (const AMsgUID: String; const AMBName: String): Boolean;
{CC8: Added UID version of CopyMsgs...}
function UIDCopyMsgs(const AMsgUIDList: TStringList; 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?}
{CC8: UIDRetrieveAllHeaders is removed, it makes no sense when you think about it,
because it would need a sparse array because of missing UIDs in sequence.}
{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; {Do not Localize}
{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; {Do not Localize}
{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 its 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 }
procedure GetInternalResponse (const ATag: String); overload;
procedure GetInternalResponse; overload;
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;
procedure GetInternalLineResponse (const ATag: String);
procedure RemoveAnyAdditionalResponses;
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;
function ReadLnWait: string;
procedure WriteLn(AOut: string); reintroduce;
{ 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}
end;
implementation
uses
IdEMailAddress,
IdException,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -