2008-04-24 10:12:01 +03:00
|
|
|
{==============================================================================|
|
2015-02-16 15:54:14 +02:00
|
|
|
| Project : Ararat Synapse | 002.005.004 |
|
2008-04-24 10:12:01 +03:00
|
|
|
|==============================================================================|
|
2008-04-24 10:20:39 +03:00
|
|
|
| Content: IMAP4rev1 client |
|
2008-04-24 10:12:01 +03:00
|
|
|
|==============================================================================|
|
2015-02-16 15:54:14 +02:00
|
|
|
| Copyright (c)1999-2015, Lukas Gebauer |
|
2008-04-24 10:20:39 +03:00
|
|
|
| All rights reserved. |
|
2008-04-24 10:12:01 +03:00
|
|
|
| |
|
2008-04-24 10:20:39 +03:00
|
|
|
| Redistribution and use in source and binary forms, with or without |
|
|
|
|
| modification, are permitted provided that the following conditions are met: |
|
|
|
|
| |
|
|
|
|
| Redistributions of source code must retain the above copyright notice, this |
|
|
|
|
| list of conditions and the following disclaimer. |
|
|
|
|
| |
|
|
|
|
| Redistributions in binary form must reproduce the above copyright notice, |
|
|
|
|
| this list of conditions and the following disclaimer in the documentation |
|
|
|
|
| and/or other materials provided with the distribution. |
|
|
|
|
| |
|
|
|
|
| Neither the name of Lukas Gebauer nor the names of its contributors may |
|
|
|
|
| be used to endorse or promote products derived from this software without |
|
|
|
|
| specific prior written permission. |
|
|
|
|
| |
|
|
|
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
|
|
|
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
|
|
|
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
|
|
|
| ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR |
|
|
|
|
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
|
|
|
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
|
|
|
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
|
|
|
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
|
|
|
| LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
|
|
|
| OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
|
|
|
|
| DAMAGE. |
|
2008-04-24 10:12:01 +03:00
|
|
|
|==============================================================================|
|
|
|
|
| The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
|
2015-02-16 15:54:14 +02:00
|
|
|
| Portions created by Lukas Gebauer are Copyright (c)2001-2015. |
|
2008-04-24 10:12:01 +03:00
|
|
|
| All Rights Reserved. |
|
|
|
|
|==============================================================================|
|
|
|
|
| Contributor(s): |
|
|
|
|
|==============================================================================|
|
|
|
|
| History: see HISTORY.HTM from distribution package |
|
|
|
|
| (Found at URL: http://www.ararat.cz/synapse/) |
|
|
|
|
|==============================================================================}
|
|
|
|
|
2008-04-24 10:29:09 +03:00
|
|
|
{:@abstract(IMAP4 rev1 protocol client)
|
|
|
|
|
|
|
|
Used RFC: RFC-2060, RFC-2595
|
|
|
|
}
|
2008-04-24 10:12:01 +03:00
|
|
|
|
2008-04-24 10:25:18 +03:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE DELPHI}
|
|
|
|
{$ENDIF}
|
|
|
|
{$H+}
|
|
|
|
|
2010-02-03 16:53:03 +02:00
|
|
|
{$IFDEF UNICODE}
|
|
|
|
{$WARN IMPLICIT_STRING_CAST OFF}
|
|
|
|
{$WARN IMPLICIT_STRING_CAST_LOSS OFF}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2008-04-24 10:25:18 +03:00
|
|
|
unit imapsend;
|
2008-04-24 10:12:01 +03:00
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
SysUtils, Classes,
|
2008-04-24 10:29:09 +03:00
|
|
|
blcksock, synautil;
|
2008-04-24 10:12:01 +03:00
|
|
|
|
|
|
|
const
|
|
|
|
cIMAPProtocol = '143';
|
|
|
|
|
|
|
|
type
|
2008-04-24 10:29:09 +03:00
|
|
|
{:@abstract(Implementation of IMAP4 protocol.)
|
|
|
|
Note: Are you missing properties for setting Username and Password? Look to
|
|
|
|
parent @link(TSynaClient) object!
|
|
|
|
|
|
|
|
Are you missing properties for specify server address and port? Look to
|
|
|
|
parent @link(TSynaClient) too!}
|
2008-04-24 10:20:39 +03:00
|
|
|
TIMAPSend = class(TSynaClient)
|
2008-04-24 10:29:09 +03:00
|
|
|
protected
|
2008-04-24 10:12:01 +03:00
|
|
|
FSock: TTCPBlockSocket;
|
|
|
|
FTagCommand: integer;
|
|
|
|
FResultString: string;
|
|
|
|
FFullResult: TStringList;
|
|
|
|
FIMAPcap: TStringList;
|
|
|
|
FAuthDone: Boolean;
|
|
|
|
FSelectedFolder: string;
|
|
|
|
FSelectedCount: integer;
|
|
|
|
FSelectedRecent: integer;
|
|
|
|
FSelectedUIDvalidity: integer;
|
|
|
|
FUID: Boolean;
|
2008-04-24 10:18:26 +03:00
|
|
|
FAutoTLS: Boolean;
|
|
|
|
FFullSSL: Boolean;
|
2008-04-24 10:12:01 +03:00
|
|
|
function ReadResult: string;
|
|
|
|
function AuthLogin: Boolean;
|
|
|
|
function Connect: Boolean;
|
|
|
|
procedure ParseMess(Value:TStrings);
|
|
|
|
procedure ParseFolderList(Value:TStrings);
|
|
|
|
procedure ParseSelect;
|
|
|
|
procedure ParseSearch(Value:TStrings);
|
2008-04-24 10:23:38 +03:00
|
|
|
procedure ProcessLiterals;
|
2008-04-24 10:12:01 +03:00
|
|
|
public
|
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:By this function you can call any IMAP command. Result of this command is
|
|
|
|
in adequate properties.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function IMAPcommand(Value: string): string;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:By this function you can call any IMAP command what need upload any data.
|
|
|
|
Result of this command is in adequate properties.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function IMAPuploadCommand(Value: string; const Data:TStrings): string;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Call CAPABILITY command and fill IMAPcap property by new values.}
|
2008-04-24 10:18:26 +03:00
|
|
|
function Capability: Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Connect to IMAP server and do login to this server. This command begin
|
|
|
|
session.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function Login: Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Disconnect from IMAP server and terminate session session. If exists some
|
|
|
|
deleted and non-purged messages, these messages are not deleted!}
|
|
|
|
function Logout: Boolean;
|
|
|
|
|
|
|
|
{:Do NOOP. It is for prevent disconnect by timeout.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function NoOp: Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Lists folder names. You may specify level of listing. If you specify
|
|
|
|
FromFolder as empty string, return is all folders in system.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function List(FromFolder: string; const FolderList: TStrings): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Lists folder names what match search criteria. You may specify level of
|
|
|
|
listing. If you specify FromFolder as empty string, return is all folders
|
|
|
|
in system.}
|
|
|
|
function ListSearch(FromFolder, Search: string; const FolderList: TStrings): Boolean;
|
|
|
|
|
|
|
|
{:Lists subscribed folder names. You may specify level of listing. If you
|
|
|
|
specify FromFolder as empty string, return is all subscribed folders in
|
|
|
|
system.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function ListSubscribed(FromFolder: string; const FolderList: TStrings): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Lists subscribed folder names what matching search criteria. You may
|
|
|
|
specify level of listing. If you specify FromFolder as empty string, return
|
|
|
|
is all subscribed folders in system.}
|
|
|
|
function ListSearchSubscribed(FromFolder, Search: string; const FolderList: TStrings): Boolean;
|
|
|
|
|
|
|
|
{:Create a new folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function CreateFolder(FolderName: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Delete a folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function DeleteFolder(FolderName: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Rename folder names.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function RenameFolder(FolderName, NewFolderName: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Subscribe folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function SubscribeFolder(FolderName: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Unsubscribe folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function UnsubscribeFolder(FolderName: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Select folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function SelectFolder(FolderName: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Select folder, but only for reading. Any changes are not allowed!}
|
2008-04-24 10:12:01 +03:00
|
|
|
function SelectROFolder(FolderName: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Close a folder. (end of Selected state)}
|
2008-04-24 10:12:01 +03:00
|
|
|
function CloseFolder: Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Ask for given status of folder. I.e. if you specify as value 'UNSEEN',
|
|
|
|
result is number of unseen messages in folder. For another status
|
|
|
|
indentificator check IMAP documentation and documentation of your IMAP
|
|
|
|
server (each IMAP server can have their own statuses.)}
|
2008-04-24 10:12:01 +03:00
|
|
|
function StatusFolder(FolderName, Value: string): integer;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Hardly delete all messages marked as 'deleted' in current selected folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function ExpungeFolder: Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Touch to folder. (use as update status of folder, etc.)}
|
2008-04-24 10:12:01 +03:00
|
|
|
function CheckFolder: Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Append given message to specified folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function AppendMess(ToFolder: string; const Mess: TStrings): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
2008-04-24 10:42:16 +03:00
|
|
|
{:'Delete' message from current selected folder. It mark message as Deleted.
|
|
|
|
Real deleting will be done after sucessfull @link(CloseFolder) or
|
2008-04-24 10:29:09 +03:00
|
|
|
@link(ExpungeFolder)}
|
2008-04-24 10:12:01 +03:00
|
|
|
function DeleteMess(MessID: integer): boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Get full message from specified message in selected folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function FetchMess(MessID: integer; const Mess: TStrings): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Get message headers only from specified message in selected folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function FetchHeader(MessID: integer; const Headers: TStrings): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Return message size of specified message from current selected folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function MessageSize(MessID: integer): integer;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Copy message from current selected folder to another folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function CopyMess(MessID: integer; ToFolder: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Return message numbers from currently selected folder as result
|
|
|
|
of searching. Search criteria is very complex language (see to IMAP
|
|
|
|
specification) similar to SQL (but not same syntax!).}
|
2008-04-24 10:12:01 +03:00
|
|
|
function SearchMess(Criteria: string; const FoundMess: TStrings): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Sets flags of message from current selected folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function SetFlagsMess(MessID: integer; Flags: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Gets flags of message from current selected folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function GetFlagsMess(MessID: integer; var Flags: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Add flags to message's flags.}
|
2008-04-24 10:25:18 +03:00
|
|
|
function AddFlagsMess(MessID: integer; Flags: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Remove flags from message's flags.}
|
2008-04-24 10:25:18 +03:00
|
|
|
function DelFlagsMess(MessID: integer; Flags: string): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Call STARTTLS command for upgrade connection to SSL/TLS mode.}
|
2008-04-24 10:18:26 +03:00
|
|
|
function StartTLS: Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:return UID of requested message ID.}
|
2008-04-24 10:22:17 +03:00
|
|
|
function GetUID(MessID: integer; var UID : Integer): Boolean;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Try to find given capabily in capabilty string returned from IMAP server.}
|
2008-04-24 10:12:01 +03:00
|
|
|
function FindCap(const Value: string): string;
|
|
|
|
published
|
2008-04-24 10:29:09 +03:00
|
|
|
{:Status line with result of last operation.}
|
2008-04-24 10:12:01 +03:00
|
|
|
property ResultString: string read FResultString;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Full result of last IMAP operation.}
|
2008-04-24 10:12:01 +03:00
|
|
|
property FullResult: TStringList read FFullResult;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:List of server capabilites.}
|
2008-04-24 10:12:01 +03:00
|
|
|
property IMAPcap: TStringList read FIMAPcap;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Authorization is successful done.}
|
2008-04-24 10:12:01 +03:00
|
|
|
property AuthDone: Boolean read FAuthDone;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Turn on or off usage of UID (unicate identificator) of messages instead
|
|
|
|
only sequence numbers.}
|
2008-04-24 10:12:01 +03:00
|
|
|
property UID: Boolean read FUID Write FUID;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Name of currently selected folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
property SelectedFolder: string read FSelectedFolder;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Count of messages in currently selected folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
property SelectedCount: integer read FSelectedCount;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:Count of not-visited messages in currently selected folder.}
|
2008-04-24 10:12:01 +03:00
|
|
|
property SelectedRecent: integer read FSelectedRecent;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:This number with name of folder is unique indentificator of folder.
|
|
|
|
(If someone delete folder and next create new folder with exactly same name
|
|
|
|
of folder, this number is must be different!)}
|
2008-04-24 10:12:01 +03:00
|
|
|
property SelectedUIDvalidity: integer read FSelectedUIDvalidity;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:If is set to true, then upgrade to SSL/TLS mode if remote server support it.}
|
2008-04-24 10:18:26 +03:00
|
|
|
property AutoTLS: Boolean read FAutoTLS Write FAutoTLS;
|
2008-04-24 10:29:09 +03:00
|
|
|
|
|
|
|
{:SSL/TLS mode is used from first contact to server. Servers with full
|
|
|
|
SSL/TLS mode usualy using non-standard TCP port!}
|
2008-04-24 10:18:26 +03:00
|
|
|
property FullSSL: Boolean read FFullSSL Write FFullSSL;
|
2008-04-24 10:39:12 +03:00
|
|
|
|
2008-04-24 10:29:09 +03:00
|
|
|
{:Socket object used for TCP/IP operation. Good for seting OnStatus hook, etc.}
|
2008-04-24 10:23:38 +03:00
|
|
|
property Sock: TTCPBlockSocket read FSock;
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
constructor TIMAPSend.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
FFullResult := TStringList.Create;
|
|
|
|
FIMAPcap := TStringList.Create;
|
|
|
|
FSock := TTCPBlockSocket.Create;
|
2010-01-04 11:47:36 +02:00
|
|
|
FSock.Owner := self;
|
2008-04-24 10:22:17 +03:00
|
|
|
FSock.ConvertLineEnd := True;
|
2008-04-24 10:12:01 +03:00
|
|
|
FSock.SizeRecvBuffer := 32768;
|
|
|
|
FSock.SizeSendBuffer := 32768;
|
2008-04-24 10:23:38 +03:00
|
|
|
FTimeout := 60000;
|
2008-04-24 10:20:39 +03:00
|
|
|
FTargetPort := cIMAPProtocol;
|
2008-04-24 10:12:01 +03:00
|
|
|
FTagCommand := 0;
|
|
|
|
FSelectedFolder := '';
|
|
|
|
FSelectedCount := 0;
|
|
|
|
FSelectedRecent := 0;
|
|
|
|
FSelectedUIDvalidity := 0;
|
|
|
|
FUID := False;
|
2008-04-24 10:18:26 +03:00
|
|
|
FAutoTLS := False;
|
|
|
|
FFullSSL := False;
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TIMAPSend.Destroy;
|
|
|
|
begin
|
|
|
|
FSock.Free;
|
|
|
|
FIMAPcap.Free;
|
|
|
|
FFullResult.Free;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TIMAPSend.ReadResult: string;
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
x, l: integer;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
FFullResult.Clear;
|
|
|
|
FResultString := '';
|
|
|
|
repeat
|
|
|
|
s := FSock.RecvString(FTimeout);
|
|
|
|
if Pos('S' + IntToStr(FTagCommand) + ' ', s) = 1 then
|
|
|
|
begin
|
|
|
|
FResultString := s;
|
|
|
|
break;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
FFullResult.Add(s);
|
|
|
|
if (s <> '') and (s[Length(s)]='}') then
|
|
|
|
begin
|
|
|
|
s := Copy(s, 1, Length(s) - 1);
|
|
|
|
x := RPos('{', s);
|
|
|
|
s := Copy(s, x + 1, Length(s) - x);
|
|
|
|
l := StrToIntDef(s, -1);
|
|
|
|
if l <> -1 then
|
|
|
|
begin
|
2008-04-24 10:22:17 +03:00
|
|
|
s := FSock.RecvBufferStr(l, FTimeout);
|
2008-04-24 10:12:01 +03:00
|
|
|
FFullResult.Add(s);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
until FSock.LastError <> 0;
|
2008-04-24 10:29:09 +03:00
|
|
|
s := Trim(separateright(FResultString, ' '));
|
|
|
|
Result:=uppercase(Trim(separateleft(s, ' ')));
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
|
|
|
|
2008-04-24 10:23:38 +03:00
|
|
|
procedure TIMAPSend.ProcessLiterals;
|
|
|
|
var
|
|
|
|
l: TStringList;
|
|
|
|
n, x: integer;
|
|
|
|
b: integer;
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
l := TStringList.Create;
|
|
|
|
try
|
|
|
|
l.Assign(FFullResult);
|
|
|
|
FFullResult.Clear;
|
|
|
|
b := 0;
|
|
|
|
for n := 0 to l.Count - 1 do
|
|
|
|
begin
|
|
|
|
s := l[n];
|
|
|
|
if b > 0 then
|
|
|
|
begin
|
|
|
|
FFullResult[FFullresult.Count - 1] :=
|
|
|
|
FFullResult[FFullresult.Count - 1] + s;
|
|
|
|
inc(b);
|
|
|
|
if b > 2 then
|
|
|
|
b := 0;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if (s <> '') and (s[Length(s)]='}') then
|
|
|
|
begin
|
|
|
|
x := RPos('{', s);
|
|
|
|
Delete(s, x, Length(s) - x + 1);
|
|
|
|
b := 1;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
b := 0;
|
|
|
|
FFullResult.Add(s);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
l.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
function TIMAPSend.IMAPcommand(Value: string): string;
|
|
|
|
begin
|
|
|
|
Inc(FTagCommand);
|
|
|
|
FSock.SendString('S' + IntToStr(FTagCommand) + ' ' + Value + CRLF);
|
|
|
|
Result := ReadResult;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.IMAPuploadCommand(Value: string; const Data:TStrings): string;
|
|
|
|
var
|
|
|
|
l: integer;
|
|
|
|
begin
|
|
|
|
Inc(FTagCommand);
|
|
|
|
l := Length(Data.Text);
|
2008-04-24 10:22:17 +03:00
|
|
|
FSock.SendString('S' + IntToStr(FTagCommand) + ' ' + Value + ' {'+ IntToStr(l) + '}' + CRLF);
|
|
|
|
FSock.RecvString(FTimeout);
|
2008-04-24 10:12:01 +03:00
|
|
|
FSock.SendString(Data.Text + CRLF);
|
|
|
|
Result := ReadResult;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TIMAPSend.ParseMess(Value:TStrings);
|
|
|
|
var
|
|
|
|
n: integer;
|
|
|
|
begin
|
|
|
|
Value.Clear;
|
|
|
|
for n := 0 to FFullResult.Count - 2 do
|
2012-03-13 18:21:38 +03:00
|
|
|
if (length(FFullResult[n]) > 0) and (FFullResult[n][Length(FFullResult[n])] = '}') then
|
2008-04-24 10:12:01 +03:00
|
|
|
begin
|
|
|
|
Value.Text := FFullResult[n + 1];
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TIMAPSend.ParseFolderList(Value:TStrings);
|
|
|
|
var
|
|
|
|
n, x: integer;
|
|
|
|
s: string;
|
|
|
|
begin
|
2008-04-24 10:23:38 +03:00
|
|
|
ProcessLiterals;
|
2008-04-24 10:12:01 +03:00
|
|
|
Value.Clear;
|
|
|
|
for n := 0 to FFullResult.Count - 1 do
|
|
|
|
begin
|
|
|
|
s := FFullResult[n];
|
2008-04-24 10:22:17 +03:00
|
|
|
if (s <> '') and (Pos('\NOSELECT', UpperCase(s)) = 0) then
|
|
|
|
begin
|
|
|
|
if s[Length(s)] = '"' then
|
|
|
|
begin
|
|
|
|
Delete(s, Length(s), 1);
|
|
|
|
x := RPos('"', s);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
x := RPos(' ', s);
|
|
|
|
if (x > 0) then
|
|
|
|
Value.Add(Copy(s, x + 1, Length(s) - x));
|
|
|
|
end;
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TIMAPSend.ParseSelect;
|
|
|
|
var
|
|
|
|
n: integer;
|
|
|
|
s, t: string;
|
|
|
|
begin
|
2008-04-24 10:23:38 +03:00
|
|
|
ProcessLiterals;
|
2008-04-24 10:12:01 +03:00
|
|
|
FSelectedCount := 0;
|
|
|
|
FSelectedRecent := 0;
|
|
|
|
FSelectedUIDvalidity := 0;
|
|
|
|
for n := 0 to FFullResult.Count - 1 do
|
|
|
|
begin
|
|
|
|
s := uppercase(FFullResult[n]);
|
|
|
|
if Pos(' EXISTS', s) > 0 then
|
|
|
|
begin
|
2008-04-24 10:29:09 +03:00
|
|
|
t := Trim(separateleft(s, ' EXISTS'));
|
|
|
|
t := Trim(separateright(t, '* '));
|
2008-04-24 10:12:01 +03:00
|
|
|
FSelectedCount := StrToIntDef(t, 0);
|
|
|
|
end;
|
|
|
|
if Pos(' RECENT', s) > 0 then
|
|
|
|
begin
|
2008-04-24 10:29:09 +03:00
|
|
|
t := Trim(separateleft(s, ' RECENT'));
|
|
|
|
t := Trim(separateright(t, '* '));
|
2008-04-24 10:12:01 +03:00
|
|
|
FSelectedRecent := StrToIntDef(t, 0);
|
|
|
|
end;
|
|
|
|
if Pos('UIDVALIDITY', s) > 0 then
|
|
|
|
begin
|
2008-04-24 10:29:09 +03:00
|
|
|
t := Trim(separateright(s, 'UIDVALIDITY '));
|
|
|
|
t := Trim(separateleft(t, ']'));
|
2008-04-24 10:12:01 +03:00
|
|
|
FSelectedUIDvalidity := StrToIntDef(t, 0);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TIMAPSend.ParseSearch(Value:TStrings);
|
|
|
|
var
|
|
|
|
n: integer;
|
|
|
|
s: string;
|
|
|
|
begin
|
2008-04-24 10:23:38 +03:00
|
|
|
ProcessLiterals;
|
2008-04-24 10:12:01 +03:00
|
|
|
Value.Clear;
|
|
|
|
for n := 0 to FFullResult.Count - 1 do
|
|
|
|
begin
|
|
|
|
s := uppercase(FFullResult[n]);
|
|
|
|
if Pos('* SEARCH', s) = 1 then
|
|
|
|
begin
|
2008-04-24 10:29:09 +03:00
|
|
|
s := Trim(SeparateRight(s, '* SEARCH'));
|
2008-04-24 10:12:01 +03:00
|
|
|
while s <> '' do
|
|
|
|
Value.Add(Fetch(s, ' '));
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.FindCap(const Value: string): string;
|
|
|
|
var
|
|
|
|
n: Integer;
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
s := UpperCase(Value);
|
|
|
|
Result := '';
|
|
|
|
for n := 0 to FIMAPcap.Count - 1 do
|
|
|
|
if Pos(s, UpperCase(FIMAPcap[n])) = 1 then
|
|
|
|
begin
|
|
|
|
Result := FIMAPcap[n];
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.AuthLogin: Boolean;
|
|
|
|
begin
|
2008-04-24 10:23:38 +03:00
|
|
|
Result := IMAPcommand('LOGIN "' + FUsername + '" "' + FPassword + '"') = 'OK';
|
2015-02-16 15:54:14 +02:00
|
|
|
if Result then
|
|
|
|
FAuthDone := True;
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.Connect: Boolean;
|
|
|
|
begin
|
|
|
|
FSock.CloseSocket;
|
2008-04-24 10:23:38 +03:00
|
|
|
FSock.Bind(FIPInterface, cAnyPort);
|
|
|
|
if FSock.LastError = 0 then
|
|
|
|
FSock.Connect(FTargetHost, FTargetPort);
|
2008-04-24 10:39:12 +03:00
|
|
|
if FSock.LastError = 0 then
|
|
|
|
if FFullSSL then
|
|
|
|
FSock.SSLDoConnect;
|
2008-04-24 10:12:01 +03:00
|
|
|
Result := FSock.LastError = 0;
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:18:26 +03:00
|
|
|
function TIMAPSend.Capability: Boolean;
|
2008-04-24 10:12:01 +03:00
|
|
|
var
|
|
|
|
n: Integer;
|
|
|
|
s, t: string;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
FIMAPcap.Clear;
|
|
|
|
s := IMAPcommand('CAPABILITY');
|
|
|
|
if s = 'OK' then
|
|
|
|
begin
|
2008-04-24 10:23:38 +03:00
|
|
|
ProcessLiterals;
|
2008-04-24 10:12:01 +03:00
|
|
|
for n := 0 to FFullResult.Count - 1 do
|
|
|
|
if Pos('* CAPABILITY ', FFullResult[n]) = 1 then
|
|
|
|
begin
|
2008-04-24 10:29:09 +03:00
|
|
|
s := Trim(SeparateRight(FFullResult[n], '* CAPABILITY '));
|
2008-04-24 10:12:01 +03:00
|
|
|
while not (s = '') do
|
|
|
|
begin
|
2008-04-24 10:29:09 +03:00
|
|
|
t := Trim(separateleft(s, ' '));
|
|
|
|
s := Trim(separateright(s, ' '));
|
2008-04-24 10:12:01 +03:00
|
|
|
if s = t then
|
|
|
|
s := '';
|
|
|
|
FIMAPcap.Add(t);
|
|
|
|
end;
|
|
|
|
end;
|
2008-04-24 10:18:26 +03:00
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.Login: Boolean;
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
FSelectedFolder := '';
|
|
|
|
FSelectedCount := 0;
|
|
|
|
FSelectedRecent := 0;
|
|
|
|
FSelectedUIDvalidity := 0;
|
|
|
|
Result := False;
|
|
|
|
FAuthDone := False;
|
|
|
|
if not Connect then
|
|
|
|
Exit;
|
|
|
|
s := FSock.RecvString(FTimeout);
|
|
|
|
if Pos('* PREAUTH', s) = 1 then
|
|
|
|
FAuthDone := True
|
|
|
|
else
|
|
|
|
if Pos('* OK', s) = 1 then
|
|
|
|
FAuthDone := False
|
|
|
|
else
|
|
|
|
Exit;
|
|
|
|
if Capability then
|
|
|
|
begin
|
2008-04-24 10:12:01 +03:00
|
|
|
if Findcap('IMAP4rev1') = '' then
|
|
|
|
Exit;
|
2008-04-24 10:18:26 +03:00
|
|
|
if FAutoTLS and (Findcap('STARTTLS') <> '') then
|
|
|
|
if StartTLS then
|
|
|
|
Capability;
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
|
|
|
Result := AuthLogin;
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:29:09 +03:00
|
|
|
function TIMAPSend.Logout: Boolean;
|
2008-04-24 10:12:01 +03:00
|
|
|
begin
|
2008-04-24 10:29:09 +03:00
|
|
|
Result := IMAPcommand('LOGOUT') = 'OK';
|
2008-04-24 10:12:01 +03:00
|
|
|
FSelectedFolder := '';
|
|
|
|
FSock.CloseSocket;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.NoOp: Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('NOOP') = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.List(FromFolder: string; const FolderList: TStrings): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('LIST "' + FromFolder + '" *') = 'OK';
|
|
|
|
ParseFolderList(FolderList);
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:29:09 +03:00
|
|
|
function TIMAPSend.ListSearch(FromFolder, Search: string; const FolderList: TStrings): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('LIST "' + FromFolder + '" "' + Search +'"') = 'OK';
|
|
|
|
ParseFolderList(FolderList);
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
function TIMAPSend.ListSubscribed(FromFolder: string; const FolderList: TStrings): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('LSUB "' + FromFolder + '" *') = 'OK';
|
|
|
|
ParseFolderList(FolderList);
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:29:09 +03:00
|
|
|
function TIMAPSend.ListSearchSubscribed(FromFolder, Search: string; const FolderList: TStrings): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('LSUB "' + FromFolder + '" "' + Search +'"') = 'OK';
|
|
|
|
ParseFolderList(FolderList);
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
function TIMAPSend.CreateFolder(FolderName: string): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('CREATE "' + FolderName + '"') = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.DeleteFolder(FolderName: string): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('DELETE "' + FolderName + '"') = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.RenameFolder(FolderName, NewFolderName: string): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('RENAME "' + FolderName + '" "' + NewFolderName + '"') = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.SubscribeFolder(FolderName: string): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('SUBSCRIBE "' + FolderName + '"') = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.UnsubscribeFolder(FolderName: string): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('UNSUBSCRIBE "' + FolderName + '"') = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.SelectFolder(FolderName: string): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('SELECT "' + FolderName + '"') = 'OK';
|
|
|
|
FSelectedFolder := FolderName;
|
|
|
|
ParseSelect;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.SelectROFolder(FolderName: string): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('EXAMINE "' + FolderName + '"') = 'OK';
|
|
|
|
FSelectedFolder := FolderName;
|
|
|
|
ParseSelect;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.CloseFolder: Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('CLOSE') = 'OK';
|
|
|
|
FSelectedFolder := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.StatusFolder(FolderName, Value: string): integer;
|
|
|
|
var
|
|
|
|
n: integer;
|
|
|
|
s, t: string;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
Value := Uppercase(Value);
|
|
|
|
if IMAPcommand('STATUS "' + FolderName + '" (' + Value + ')' ) = 'OK' then
|
2008-04-24 10:23:38 +03:00
|
|
|
begin
|
|
|
|
ProcessLiterals;
|
2008-04-24 10:12:01 +03:00
|
|
|
for n := 0 to FFullResult.Count - 1 do
|
|
|
|
begin
|
2008-04-24 10:25:18 +03:00
|
|
|
s := FFullResult[n];
|
|
|
|
// s := UpperCase(FFullResult[n]);
|
2008-04-24 10:23:38 +03:00
|
|
|
if (Pos('* ', s) = 1) and (Pos(FolderName, s) >= 1) and (Pos(Value, s) > 0 ) then
|
2008-04-24 10:12:01 +03:00
|
|
|
begin
|
|
|
|
t := SeparateRight(s, Value);
|
|
|
|
t := SeparateLeft(t, ')');
|
|
|
|
t := trim(t);
|
|
|
|
Result := StrToIntDef(t, -1);
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
2008-04-24 10:23:38 +03:00
|
|
|
end;
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.ExpungeFolder: Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('EXPUNGE') = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.CheckFolder: Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPcommand('CHECK') = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.AppendMess(ToFolder: string; const Mess: TStrings): Boolean;
|
|
|
|
begin
|
|
|
|
Result := IMAPuploadCommand('APPEND "' + ToFolder + '"', Mess) = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.DeleteMess(MessID: integer): boolean;
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
s := 'STORE ' + IntToStr(MessID) + ' +FLAGS.SILENT (\Deleted)';
|
|
|
|
if FUID then
|
|
|
|
s := 'UID ' + s;
|
|
|
|
Result := IMAPcommand(s) = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.FetchMess(MessID: integer; const Mess: TStrings): Boolean;
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
s := 'FETCH ' + IntToStr(MessID) + ' (RFC822)';
|
|
|
|
if FUID then
|
|
|
|
s := 'UID ' + s;
|
|
|
|
Result := IMAPcommand(s) = 'OK';
|
|
|
|
ParseMess(Mess);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.FetchHeader(MessID: integer; const Headers: TStrings): Boolean;
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
s := 'FETCH ' + IntToStr(MessID) + ' (RFC822.HEADER)';
|
|
|
|
if FUID then
|
|
|
|
s := 'UID ' + s;
|
|
|
|
Result := IMAPcommand(s) = 'OK';
|
|
|
|
ParseMess(Headers);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.MessageSize(MessID: integer): integer;
|
|
|
|
var
|
|
|
|
n: integer;
|
|
|
|
s, t: string;
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
s := 'FETCH ' + IntToStr(MessID) + ' (RFC822.SIZE)';
|
|
|
|
if FUID then
|
|
|
|
s := 'UID ' + s;
|
|
|
|
if IMAPcommand(s) = 'OK' then
|
2008-04-24 10:23:38 +03:00
|
|
|
begin
|
|
|
|
ProcessLiterals;
|
2008-04-24 10:12:01 +03:00
|
|
|
for n := 0 to FFullResult.Count - 1 do
|
|
|
|
begin
|
|
|
|
s := UpperCase(FFullResult[n]);
|
|
|
|
if (Pos('* ', s) = 1) and (Pos('RFC822.SIZE', s) > 0 ) then
|
|
|
|
begin
|
|
|
|
t := SeparateRight(s, 'RFC822.SIZE ');
|
2008-04-24 10:29:09 +03:00
|
|
|
t := Trim(SeparateLeft(t, ')'));
|
2008-04-24 10:39:12 +03:00
|
|
|
t := Trim(SeparateLeft(t, ' '));
|
2008-04-24 10:12:01 +03:00
|
|
|
Result := StrToIntDef(t, -1);
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
2008-04-24 10:23:38 +03:00
|
|
|
end;
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.CopyMess(MessID: integer; ToFolder: string): Boolean;
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
s := 'COPY ' + IntToStr(MessID) + ' "' + ToFolder + '"';
|
|
|
|
if FUID then
|
|
|
|
s := 'UID ' + s;
|
|
|
|
Result := IMAPcommand(s) = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.SearchMess(Criteria: string; const FoundMess: TStrings): Boolean;
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
s := 'SEARCH ' + Criteria;
|
|
|
|
if FUID then
|
|
|
|
s := 'UID ' + s;
|
|
|
|
Result := IMAPcommand(s) = 'OK';
|
|
|
|
ParseSearch(FoundMess);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.SetFlagsMess(MessID: integer; Flags: string): Boolean;
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
s := 'STORE ' + IntToStr(MessID) + ' FLAGS.SILENT (' + Flags + ')';
|
|
|
|
if FUID then
|
|
|
|
s := 'UID ' + s;
|
|
|
|
Result := IMAPcommand(s) = 'OK';
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:25:18 +03:00
|
|
|
function TIMAPSend.AddFlagsMess(MessID: integer; Flags: string): Boolean;
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
s := 'STORE ' + IntToStr(MessID) + ' +FLAGS.SILENT (' + Flags + ')';
|
|
|
|
if FUID then
|
|
|
|
s := 'UID ' + s;
|
|
|
|
Result := IMAPcommand(s) = 'OK';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TIMAPSend.DelFlagsMess(MessID: integer; Flags: string): Boolean;
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
begin
|
|
|
|
s := 'STORE ' + IntToStr(MessID) + ' -FLAGS.SILENT (' + Flags + ')';
|
|
|
|
if FUID then
|
|
|
|
s := 'UID ' + s;
|
|
|
|
Result := IMAPcommand(s) = 'OK';
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
function TIMAPSend.GetFlagsMess(MessID: integer; var Flags: string): Boolean;
|
|
|
|
var
|
|
|
|
s: string;
|
|
|
|
n: integer;
|
|
|
|
begin
|
|
|
|
Flags := '';
|
|
|
|
s := 'FETCH ' + IntToStr(MessID) + ' (FLAGS)';
|
|
|
|
if FUID then
|
|
|
|
s := 'UID ' + s;
|
|
|
|
Result := IMAPcommand(s) = 'OK';
|
2008-04-24 10:23:38 +03:00
|
|
|
ProcessLiterals;
|
2008-04-24 10:12:01 +03:00
|
|
|
for n := 0 to FFullResult.Count - 1 do
|
|
|
|
begin
|
|
|
|
s := uppercase(FFullResult[n]);
|
2008-04-24 10:22:17 +03:00
|
|
|
if (Pos('* ', s) = 1) and (Pos('FLAGS', s) > 0 ) then
|
2008-04-24 10:12:01 +03:00
|
|
|
begin
|
|
|
|
s := SeparateRight(s, 'FLAGS');
|
|
|
|
s := Separateright(s, '(');
|
2008-04-24 10:29:09 +03:00
|
|
|
Flags := Trim(SeparateLeft(s, ')'));
|
2008-04-24 10:12:01 +03:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:18:26 +03:00
|
|
|
function TIMAPSend.StartTLS: Boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
if FindCap('STARTTLS') <> '' then
|
|
|
|
begin
|
|
|
|
if IMAPcommand('STARTTLS') = 'OK' then
|
|
|
|
begin
|
|
|
|
Fsock.SSLDoConnect;
|
|
|
|
Result := FSock.LastError = 0;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:22:17 +03:00
|
|
|
//Paul Buskermolen <p.buskermolen@pinkroccade.com>
|
|
|
|
function TIMAPSend.GetUID(MessID: integer; var UID : Integer): boolean;
|
|
|
|
var
|
|
|
|
s, sUid: string;
|
|
|
|
n: integer;
|
|
|
|
begin
|
|
|
|
sUID := '';
|
|
|
|
s := 'FETCH ' + IntToStr(MessID) + ' UID';
|
|
|
|
Result := IMAPcommand(s) = 'OK';
|
2008-04-24 10:23:38 +03:00
|
|
|
ProcessLiterals;
|
2008-04-24 10:22:17 +03:00
|
|
|
for n := 0 to FFullResult.Count - 1 do
|
|
|
|
begin
|
|
|
|
s := uppercase(FFullResult[n]);
|
|
|
|
if Pos('FETCH (UID', s) >= 1 then
|
|
|
|
begin
|
|
|
|
s := Separateright(s, '(UID ');
|
2008-04-24 10:29:09 +03:00
|
|
|
sUID := Trim(SeparateLeft(s, ')'));
|
2008-04-24 10:22:17 +03:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
UID := StrToIntDef(sUID, 0);
|
|
|
|
end;
|
|
|
|
|
2008-04-24 10:12:01 +03:00
|
|
|
{==============================================================================}
|
|
|
|
|
|
|
|
end.
|