Home About Units Download Documents Links Contact SourceForge
Units: POP3: Source

{                                                                              }
{                                  POP3 v3.05                                  }
{                                                                              }
{             This unit is copyright © 2000-2004 by David J Butler             }
{                                                                              }
{                  This unit is part of Delphi Fundamentals.                   }
{                     Its original file name is cPOP3.pas                      }
{       The latest version is available from the Fundamentals home page        }
{                     http://fundementals.sourceforge.net/                     }
{                                                                              }
{                I invite you to use this unit, free of charge.                }
{        I invite you to distibute this unit, but it must be for free.         }
{             I also invite you to contribute to its development,              }
{             but do not distribute a modified copy of this file.              }
{                                                                              }
{          A forum is available on SourceForge for general discussion          }
{             http://sourceforge.net/forum/forum.php?forum_id=2117             }
{                                                                              }
{                                                                              }
{ Documentation:                                                               }
{   See: RFC 1939, RFC 2449                                                    }
{                                                                              }
{ Revision history:                                                            }
{   2000/06/21  0.01  Initial version (TPOP3Client).                           }
{   2000/10/21  0.02  Addded TPop3Server.                                      }
{   2000/10/23  0.03  Completed TPop3Server.                                   }
{   2002/09/09  0.04  Created cPOP3Client and cPOP3Server units.               }
{   2004/02/07  3.05  Included in Fundamentals 3.                              }
{                                                                              }

{$INCLUDE ..\cDefines.inc}
unit cPOP3;

interface



{                                                                              }
{ Constants                                                                    }
{                                                                              }
const
  DefaultPOP3Port    = 110;
  DefaultPOP3PortStr = '110';

  DefaultPop3TimeOut = 5 * 60 * 1000;

  UnitVersion = '3.05';
  POP3Version = 'Fundamentals-POP3 v' + UnitVersion;

  MaxPop3LineLength      = 8192;
  MaxPop3ServerTopLength = 1024 * 1024;



{                                                                              }
{ POP3                                                                         }
{                                                                              }
function  EncodePop3Response(const OK: Boolean; const Msg: String): String;


{                                                                              }
{ APOP                                                                         }
{                                                                              }
function  DecodeAPOPStamp(const WelcomeMsg: String): String;
function  EncodeAPOPCommand(const APOPStamp, Username, Password: String): String;



implementation

uses
  { Fundamentals }
  cStrings,
  cHash;



{                                                                              }
{ POP3                                                                         }
{                                                                              }
function EncodePop3Response(const OK: Boolean; const Msg: String): String;
begin
  if OK then
    Result := '+OK' else
    Result := '-ERR';
  if Msg <> '' then
    Result := Result + ' ' + Msg;
end;



{                                                                              }
{ APOP                                                                         }
{                                                                              }
function DecodeAPOPStamp(const WelcomeMsg: String): String;
begin
  Result := StrCopyToChar(StrCopyFromChar(WelcomeMsg, '<'), '>', False);
end;

function EncodeAPOPCommand(const APOPStamp, Username, Password: String): String;
var S : String;
begin
  S := MD5DigestToHex(CalcMD5(APOPStamp + Password));
  ConvertLower(S);
  Result := 'APOP ' + Username + ' ' + S;
end;



end.