(**************************************************************************)
(*                                                                        *)
(*  The Weasel mail server                                                *)
(*  Copyright (C) 2022   Peter Moylan                                     *)
(*                                                                        *)
(*  This program is free software: you can redistribute it and/or modify  *)
(*  it under the terms of the GNU General Public License as published by  *)
(*  the Free Software Foundation, either version 3 of the License, or     *)
(*  (at your option) any later version.                                   *)
(*                                                                        *)
(*  This program is distributed in the hope that it will be useful,       *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *)
(*  GNU General Public License for more details.                          *)
(*                                                                        *)
(*  You should have received a copy of the GNU General Public License     *)
(*  along with this program.  If not, see <http://www.gnu.org/licenses/>. *)
(*                                                                        *)
(*  To contact author:   http://www.pmoylan.org   peter@pmoylan.org       *)
(*                                                                        *)
(**************************************************************************)

DEFINITION MODULE RelayMail;

        (********************************************************)
        (*                                                      *)
        (* Part of the SMTP server - sends mail to non-local    *)
        (*                   destinations                       *)
        (*                                                      *)
        (*  Programmer:         P. Moylan                       *)
        (*  Started:            18 November 2022                *)
        (*  Last edited:        22 November 2022                *)
        (*  Status:             Just started                    *)
        (*                                                      *)
        (********************************************************)


FROM TransLog IMPORT TransactionLogID;
FROM Sockets IMPORT Socket;
FROM SBuffers IMPORT SBuffer;
FROM Names IMPORT FilenameString;
FROM FileOps IMPORT FilePos;


PROCEDURE SetRelayParams (address: CARDINAL);

    (* Specifies which address is to be considered out principal IP     *)
    (* address, in case we have multiple interfaces.  If address = 0,   *)
    (* we allow the address to be calculated internally.                *)

PROCEDURE ConnectToHost (IPaddress: CARDINAL;  SMTPport: CARDINAL;
                      LogID: TransactionLogID;
                      VAR (*INOUT*) FailureReason: ARRAY OF CHAR): Socket;

    (* Tries to open a connection to the specified host.  Returns the   *)
    (* value NotASocket if we don't succeed; in this case, the string   *)
    (* FailureReason is given a value.                                  *)
    (* IPaddress is in network byte order.                              *)

PROCEDURE SendCommandOnly (SB: SBuffer;  ID: TransactionLogID;
                                    command: ARRAY OF CHAR;
                                    VAR (*OUT*) ConnectionLost: BOOLEAN);

PROCEDURE SendCommand (SB: SBuffer;  ID: TransactionLogID;  command: ARRAY OF CHAR;
                         VAR (*OUT*) ConnectionLost: BOOLEAN): BOOLEAN;

    (* Sends a command, returns TRUE if the command was sent OK and     *)
    (* a positive response was returned.                                *)

PROCEDURE SendFile (SB: SBuffer;  VAR (*IN*) name: FilenameString;  offset: FilePos;
                         VAR (*OUT*) ConnectionLost: BOOLEAN;
                         VAR (*OUT*) sent: CARDINAL): BOOLEAN;

    (* Sends the file, returns TRUE if it was successfully transmitted  *)
    (* and a positive response was returned.  Output parameter 'sent'   *)
    (* returns the number of bytes transmitted.                         *)

END RelayMail.

