📄 idimap4.pas
字号:
IdResourceStrings,
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}
IMAP4StatusDataItem : array [mdMessages..mdUnseen] of String =
( 'MESSAGES', {Do not Localize}
'RECENT', {Do not Localize}
'UIDNEXT', {Do not Localize}
'UIDVALIDITY', {Do not Localize}
'UNSEEN' ); {Do not Localize}
{ TIdImapSubSection }
constructor TIdImapSubSection.Create;
begin
{Make sure this are initialised properly...}
FSubSection := nil;
end;
{ TIdImapMessageParts }
constructor TIdImapMessagePart.Create(Collection: TCollection);
begin
{Make sure these are initialised properly...}
inherited Create(Collection);
FSubSection := nil;
FBoundary := ''; {Do not Localize}
end;
destructor TIdImapMessagePart.Destroy;
var
LSection, LPtr, LPtr2: TIdImapSubSection;
begin
{Destroy any subsections from the bottom up...}
while FSubSection <> nil do begin
LSection := nil;
LPtr := FSubSection;
if LPtr <> nil then begin
LPtr2 := LPtr.FSubSection;
while LPtr2 <> nil do begin
LSection := LPtr;
LPtr := LPtr2;
LPtr2 := LPtr.FSubSection;
end;
{We are at the bottom...}
LPtr.Destroy;
if LSection <> nil then begin
LSection.FSubSection := nil;
end else begin
FSubSection := nil;
end;
end;
end;
inherited Destroy;
end;
function TIdImapMessageParts.GetItem(Index: Integer): TIdImapMessagePart;
begin
Result := TIdImapMessagePart(inherited GetItem(Index));
end;
function TIdImapMessageParts.Add: TIdImapMessagePart;
begin
Result := TIdImapMessagePart(inherited Add);
end;
procedure TIdImapMessageParts.SetItem(Index: Integer; const Value: TIdImapMessagePart);
begin
inherited SetItem(Index, Value);
end;
{ TIdIMAP4 }
function TIdIMAP4.IsNumberValid(const ANumber: Integer): 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.}
begin
if ANumber < 1 then begin
raise EIdNumberInvalid.Create('Number passed as parameter is invalid, must be 1 or greater');
end;
Result := True;
end;
function TIdIMAP4.IsUIDValid(const AUID: string): 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.}
var
LN: integer;
begin
if AUID = '' then begin {Do not Localize}
raise EIdNumberInvalid.Create('Empty string passed as UID');
end;
for LN := 1 to length(AUID) do begin
if ( (Ord(AUID[LN]) < Ord('0')) or (Ord(AUID[LN]) > Ord('9')) ) then begin {Do not Localize}
raise EIdNumberInvalid.Create('UID passed as parameter is invalid, contains non-digit');
end;
end;
if StrToInt(AUID) < 1 then begin
raise EIdNumberInvalid.Create('UID passed as parameter is invalid, must be 1 or greater');
end;
Result := True;
end;
function TIdIMAP4.GetUID(const AMsgNum: Integer; var AUID: string): Boolean;
{This gets the message UID from the message relative number. Based on the code
in "function TIdIMAP4.CheckMsgSeen(const AMsgNum: Integer): Boolean;"}
var
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -