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

📄 idimap4.pas

📁 photo.163.com 相册下载器 多线程下载
💻 PAS
📖 第 1 页 / 共 5 页
字号:
}
{
{   Rev 1.3    5/7/2003 04:35:30 AM  JPMugaas
{ IMAP4 should now compile.  Started on prelimary SSL support (not finished
{ yet).
}
{
{   Rev 1.2    15/04/2003 00:57:08  CCostelloe
}
{
{   Rev 1.1    2/24/2003 09:03:06 PM  JPMugaas
}
{
{   Rev 1.0    11/13/2002 07:54:50 AM  JPMugaas
}
unit IdIMAP4;


{*

  IMAP 4 (Internet Message Access Protocol - Version 4 Rev 1)
  By Idan Cohen i_cohen@yahoo.com

  2001-FEB-27 IC: First version most of the IMAP features are implemented and
                  the core IdPOP3 features are implemented to allow a seamless
                  switch.
                  The unit is currently oriented to a session connection and not
                  to constant connection, because of that server events that are
                  raised from another user actions are not supported.

  2001-APR-18 IC: Added support for the session's connection state with a
                  special exception for commands preformed in wrong connection
                  states. Exceptions were also added for response errors.

  2001-MAY-05 IC:

  2001-Mar-13 DS: Fixed Bug # 494813 in CheckMsgSeen where LastCmdResult.Text
                  was not using the Ln index variable to access server
                  responses.

  2002-Apr-12 DS: fixed bug # 506026 in TIdIMAP4.ListSubscribedMailBoxes.  Call
                  ParseLSubResut instead of ParseListResult.

  2003-Mar-31 CC: Added GetUID and UIDSearchMailBox, sorted out some bugs (details
                  shown in comments in those functions which start with "CC:").

  2003-Apr-15 CC2:Sorted out some more bugs (details shown in comments in those
                  functions which start with "CC2:").  Set FMailBoxSeparator
                  in ParseListResult and ParseLSubResult.
                  Some IMAP servers generally return "OK completed" even if they
                  returned no data, such as passing a non-existent message
                  number to them: they possibly should return NO or BAD; the
                  functions here have been changed to return FALSE unless they
                  get good data back, even if the server answers OK.  Similar
                  change made for other functions.
                  There are a few exceptions, e.g. ListMailBoxes may only return
                  "OK completed" if the user has no mailboxes, these are noted.
                  Also, RetrieveStructure(), UIDRetrieveStructure, RetrievePart,
                  UIDRetrievePart, RetrievePartPeek and UIDRetrievePartPeek
                  added to allow user to find the structure of a message and
                  just retrieve the part or parts he needs.

  2003-Apr-30 CC3:Added functionality to retrieve the text of a message (only)
                  via RetrieveText / UIDRetrieveText / RetrieveTextPeek /
                  UIDRetrieveTextPeek.
                  Return codes now generally reflect if the function succeeded
                  instead of returning True even though function fails.

  2003-May-15 CC4:Added functionality to retrieve individual parts of a message
                  to a file, including the decoding of those parts.

  2003-May-29 CC5:Response of some servers to UID version of commands varies,
                  code changed to deal with those (UID position varies).
                  Some servers return NO such as when you request an envelope
                  for a message number that does not exist: functions return
                  False instead of throwing an exception, as was done for other
                  servers.  The general logic is that if a valid result is
                  returned from the IMAP server, return True;  if there is no
                  result (but the command is validly structured), return FALSE;
                  if the command is badly structured or if it gives a response
                  that this code does not expect, throw an exception (typically
                  when we get a BAD response instead of OK or NO).
                  Added IsNumberValid, IsUIDValid to prevent rubbishy parameters
                  being passed through to IMAP functions.
                  Sender field now filled in correctly in ParseEnvelope
                  functions.
                  All fields in ParseEnvelopeAddress are cleared out first,
                  avoids an unwitting error where some entries, such as CC list,
                  will append entries to existing entries.
                  Full test script now used that tests every TIdIMAP command,
                  more bugs eradicated.
                  First version to pass testing against both CommuniGate and
                  Cyrus IMAP servers.
                  Not tested against Microsoft Exchange, don't have an Exchange
                  account to test it against.

  2003-Jun-10 CC6:Added (UID)RetrieveEnvelopeRaw, in case the user wants to do
                  their own envelope parsing.
                  Code in RetrievePart altered to make it more consistent.
                  Altered to incorporate Indy 10's use of IdReplyIMAP4 (not
                  complete at this stage).
                  ReceiveBody added to IdIMAP4, due to the response of some
                  servers, which gets (UID)Receive(Peek) functions to work on
                  more servers.

  2003-Jun-20 CC7:ReceiveBody altered to work with Indy 10.  Made changes due to
                  LoginSASL moving from TIdMessageSASLClient to TIdSASLList.
                  Public variable FGreetingBanner added to help user identify
                  the IMAP server he is connected to (may help him decide the
                  best strategy).  Made AppendMsg work a bit better (now uses
                  platform-independent EOL and supports ExtraHeaders field).
                  Added 2nd version of AppendMsg.  Added "if Connected then "
                  to Destroy.  Attachment filenames now decoded if necessary.
                  Added support for multisection parts.

  2003-Jul-16 CC8:Added RemoveAnyAdditionalResponses.  Resolved issue of some
                  servers leaving out the trailing "NIL NIL NIL" at the end of
                  some body structures.  (UID)Retrieve(Peek) functions
                  integrated via InternalRetrieve, new method of implementing
                  these functions (all variations of Retrieve) added for Indy
                  10 based on getting message by the byte-count and then feeding
                  it into the standard message parser.
                  UIDRetrieveAllHeaders removed: it was never implemented anyway
                  but it makes no sense to retrieve a non-contiguous list which
                  would have gaps due to missing UIDs.
                  In the Indy 10 version, AppendMsg functions were altered to
                  support the sending of attachments (attachments had never
                  been supported in AppendMsg prior to this).
                  Added CopyMsg and UIDCopyMsgs to complete the command set.
  2003-Jul-30 CC9:Removed wDoublePoint so that the code is compliant with
                  the guidelines.  Allowed for servers that don't implement
                  search commands in Indy 9 (OK in 10).  InternalRetrieve
                  altered to (hopefully) deal with optional "FLAGS (\Seen)"
                  in response.
  2003-Aug-22 CCA:Yet another IMAP oddity - a server returns NIL for the
                  mailbox separator, ParseListResult modified.  Added "Length
                  (LLine) > 0)" test to stop GPF on empty line in ReceiveBody.
  2003-Sep-26 CCB:Changed SendCmd altered to try to remove anything that may
                  be unprocessed from a previous (probably failed) command.
                  This uses the property FMilliSecsToWaitToClearBuffer, which
                  defaults to 10ms.
                  Added EIdDisconnectedProbablyIdledOut, trapped in
                  GetInternalResponse.
                  Unsolicited responses now filtered out (they are now transferred
                  from FLastCmdResult.Text to a new field, FLastCmdResult.Extra,
                  leaving just the responses we want to our command in
                  FLastCmdResult.Text).
  2003-Oct-21 CCC:Original GetLineResponse merged with GetResponse to reduce
                  complexity and to add filtering unsolicited responses when
                  we are looking for single-line responses (which GetLineResponse
                  did), removed/coded-out much of these functions to make the
                  code much simpler.
                  Removed RemoveAnyAdditionalResponses, no longer needed.
                  Parsing of body structure reworked to support ParentPart concept
                  allowing parsing of indefinitely-nested MIME parts.  Note that
                  a`MIME "alternative" message with a plain-text and a html part
                  will have part[0] marked "alternative" with size 0 and ImapPartNumber
                  of 1, a part[1] of type text/plain with a ParentPart of 0 and an
                  ImapPartNumber of 1.1, and finally a part[2] of type text/html
                  again with a ParentPart of 0 and an ImapPartNumber of 1.2.
                  Imap part number changed from an integer to string, allowing
                  retrieval of IMAP sub-parts, e.g. part '3.2' is the 2nd subpart
                  of part 3.
  2003-Nov-20 CCD:Added UIDRetrievePartHeader & RetrievePartHeader.  Started to
                  use an abstracted parsing method for the command response in
                  UIDRetrieveFlags.  Added function FindHowServerCreatesFolders.
  2003-Dec-04 CCE:Copied DotNet connection changes from IdSMTP to tempoarily bypass
                  the SASL authentications until they are ported.
  2004-Jan-23 CCF:Finished .NET port, added BinHex4.0 encoding.
  2004-Apr-16 CCG:Added UTF-7 decoding/encoding code kindly written and submitted by
                  Roman Puls for encoding/decoding mailbox names.  IMAP does not use
                  standard UTF-7 code (what's new?!) so these routines are localised
                  to this unit.
*}

{ Todo -oIC :
Change the mailbox list commands so that they receive TMailBoxTree
structures and so they can store in them the mailbox name and it's attributes. }

{ Todo -oIC :
Add support for \* special flag in messages, and check for \Recent
flag in STORE command because it cant be stored (will get no reply!!!) }

{ Todo -oIC :
5.1.2.  Mailbox Namespace Naming Convention
By convention, the first hierarchical element of any mailbox name
which begins with "#" identifies the "namespace" of the remainder of
the name.  This makes it possible to disambiguate between different
types of mailbox stores, each of which have their own namespaces.
For example, implementations which offer access to USENET
newsgroups MAY use the "#news" namespace to partition the USENET
newsgroup namespace from that of other mailboxes.  Thus, the
comp.mail.misc newsgroup would have an mailbox name of
"#news.comp.mail.misc", and the name "comp.mail.misc" could refer
to a different object (e.g. a user's private mailbox). }    {Do not Localize}

{ TO BE CONSIDERED -CC :
Double-quotes in mailbox names can cause major but subtle failures.  Maybe
add the automatic stripping of double-quotes if passed in mailbox names,
to avoid ending up with ""INBOX""
}
interface

{CC3: WARNING - if the following gives a "File not found" error on compilation,
you need to add the path "C:\Program Files\Borland\Delphi7\Source\Indy" in
Project -> Options -> Directories/Conditionals -> Search Path}
{$I IdCompilerDefines.inc}

uses
    IdMessage,
    Classes,
    IdAssignedNumbers,
    IdMailBox,
    IdException,
    IdGlobal,
    IdMessageParts,
    IdMessageClient,
    IdReply,
    IdComponent,     {CC6: Now needed for ReceiveBody}
    IdMessageCoder,  {CC2: Now needed for parsing BODYSTRUCTURE}
    IdHeaderList,    {CC7: Added for 2nd version of AppendMsg}
    IdCoderHeader,   {CC7: Needed for decoding filenames}
    IdCoderMIME,
    IdCoderQuotedPrintable,
    IdCoderBinHex4,
    IdSASLCollection,     {JPM - SASL authentication for IMAP4 in Indy 10}
     IdTStrings,
    IdMessageCollection;

{ MUTF7 }

type
  EmUTF7Encode = class(EIdSilentException);
  EmUTF7Decode = class(EIdSilentException);

const
  b64Chars : array[0..63] of char =
    'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,';  {Do not Localize}

  b64Index : array [0..127] of integer = (
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,                    //  16
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,                    //  32
    -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,63,-1,-1,-1,                    //  48

⌨️ 快捷键说明

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