File: alog-facilities-smtp.ads

## Documentation

Table of Contents
Class Inheritance Tree

1.     --

2.     --  Copyright (c) 2008-2009,

3.     --  Reto Buerki, Adrian-Ken Rueegsegger

4.     --

5.     --  This file is part of Alog.

6.     --

7.     --  Alog is free software; you can redistribute it and/or modify

8.     --  it under the terms of the GNU Lesser General Public License as published

9.     --  by the Free Software Foundation; either version 2.1 of the License, or

10.     --  (at your option) any later version.

11.     --

12.     --  Alog is distributed in the hope that it will be useful,

13.     --  but WITHOUT ANY WARRANTY; without even the implied warranty of

14.     --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

15.     --  GNU Lesser General Public License for more details.

16.     --

17.     --  You should have received a copy of the GNU Lesser General Public License

18.     --  along with Alog; if not, write to the Free Software

19.     --  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,

20.     --  MA  02110-1301  USA

22.     with Ada.Characters.Latin_1;

24.     with AWS;

26.     with GNAT.Sockets;

28.     --  SMTP-Logging facility. Used to send log-messages to a configurable

29.     --  mailserver. AWS must be installed for this facility to work.

30.     package Alog.Facilities.SMTPTo API docTo specTo body is

32.        type InstanceTo API docTo body is new Alog.Facilities.InstanceTo API docTo specTo body with private;

33.        --  SMTP based logging facility.

35.        type Handle is access all InstanceTo API docTo specTo body;

37.        procedure Set_RecipientTo API docTo body

38.          (FacilityTo API docTo body : in out InstanceTo API docTo specTo body;

39.           Name     :        String;

40.           EMail    :        String);

41.        --  Set recipient for log-messages. This procedure MUST be called before

42.        --  subsequent calls to Write_Message().

44.        procedure Set_ServerTo API docTo body

45.          (FacilityTo API docTo body : in out InstanceTo API docTo specTo body;

46.           Name     :        String);

47.        --  Set server for log-messages. This procedure MUST be called before

48.        --  subsequent calls to Write_Message().

50.        procedure Set_HeaderTo API docTo body

51.          (FacilityTo API docTo body : in out InstanceTo API docTo specTo body;

52.           Header   :        String);

53.        --  Set Message-Header of log-messages.

55.        function Get_HeaderTo API docTo body (FacilityTo API docTo body : InstanceTo API docTo specTo body) return String;

56.        --  Get actual Message-Header of log-messages.

58.        --  Exceptions.

60.        No_Recipient    : exception;

61.        --  No recipient specified. Cannot send mail.

63.        No_Server       : exception;

64.        --  No server specified. Cannot send mail.

66.        Delivery_Failed : exception;

67.        --  Mail could not be delivered.

69.     private

71.        overriding

72.        procedure Write

73.          (Facility : InstanceTo API docTo specTo body;

74.           Level    : Log_LevelTo API docTo spec := Info;

75.           Msg      : String);

76.        --  Implementation of the Write procedure for SMTP.

78.        function Format_Message

79.          (Facility : InstanceTo API docTo specTo body;

80.           Level    : Log_LevelTo API docTo spec;

81.           Msg      : String)

82.           return String;

83.        --  Compose a message from Msg, Header, Loglevel, Timestamp, PID.

85.        EOL : constant Character := Ada.Characters.Latin_1.LF;

86.        --  EOL used in mail-messages.

88.        type Mail_Address is tagged record

89.           Name  : Unbounded_String;

90.           EMail : Unbounded_String;

91.        end record;

92.        --  Holds Sender / Recipient information.

94.        type InstanceTo API docTo spec is new Alog.Facilities.InstanceTo API docTo specTo body with record

95.           Server       : Unbounded_String;

96.           --  Server to connect when sending log-mails.

98.           Is_Server    : Boolean := False;

99.           --  Indicates whether a server is set.

101.           Recipient    : Mail_Address;

102.           --  Recipient for log-mails. Must be specified before calling

103.           --  Write_Message(), else No_Recipient exception is thrown.

105.           Is_Recipient : Boolean := False;

106.           --  Indicates whether a recipient is set.

108.           Sender       : Mail_Address :=

109.             (Name  => To_Unbounded_String ("alog"),

110.              EMail => To_Unbounded_String ("alog@" &

111.                GNAT.Sockets.Host_Name));

112.           --  Notification sender address/name.

114.           Subject      : Unbounded_String := To_Unbounded_String

115.             ("Log-Message");

116.           --  Subject of messages from Alog-System (default: Alog: Log-Message).

118.           Header       : Unbounded_String := To_Unbounded_String

119.             ("This is a message from the Alog-logsystem running on host "

120.              & GNAT.Sockets.Host_Name & ":" & EOL & EOL);

121.           --  Message-Header. Can be set by calling Set_Header().

122.        end record;

124.     end Alog.Facilities.SMTPTo API docTo specTo body;