PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/src/yolk-email.ads

http://github.com/ThomasLocke/yolk
Ada | 228 lines | 104 code | 25 blank | 99 comment | 0 complexity | fa6703910599ca38331bdf9abbdf7b2b MD5 | raw file
Possible License(s): AGPL-1.0
  1. -------------------------------------------------------------------------------
  2. -- --
  3. -- Copyright (C) 2010-, Thomas ¸cke --
  4. -- --
  5. -- This library is free software; you can redistribute it and/or modify --
  6. -- it under terms of the GNU General Public License as published by the --
  7. -- Free Software Foundation; either version 3, or (at your option) any --
  8. -- later version. This library is distributed in the hope that it will be --
  9. -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
  10. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
  11. -- --
  12. -- As a special exception under Section 7 of GPL version 3, you are --
  13. -- granted additional permissions described in the GCC Runtime Library --
  14. -- Exception, version 3.1, as published by the Free Software Foundation. --
  15. -- --
  16. -- You should have received a copy of the GNU General Public License and --
  17. -- a copy of the GCC Runtime Library Exception along with this program; --
  18. -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
  19. -- <http://www.gnu.org/licenses/>. --
  20. -- --
  21. -------------------------------------------------------------------------------
  22. with Ada.Containers.Vectors;
  23. with Ada.Strings.Unbounded;
  24. with GNATCOLL.Email;
  25. package Yolk.Email is
  26. Attachment_File_Not_Found : exception;
  27. -- Is raised if a file attachment is not found.
  28. No_Address_Set : exception;
  29. -- Is raised if the address component is missing in an Email_Data record.
  30. No_Sender_Set_With_Multiple_From : exception;
  31. -- Is raised when an email contains multiple From headers but no Sender
  32. -- header, as per RFC-5322, 3.6.2. http://tools.ietf.org/html/rfc5322
  33. No_SMTP_Host_Set : exception;
  34. -- Is raised if the SMTP host list is empty.
  35. type Character_Set is (US_ASCII,
  36. ISO_8859_1,
  37. ISO_8859_2,
  38. ISO_8859_3,
  39. ISO_8859_4,
  40. ISO_8859_9,
  41. ISO_8859_10,
  42. ISO_8859_13,
  43. ISO_8859_14,
  44. ISO_8859_15,
  45. Windows_1252,
  46. UTF8);
  47. -- The available character sets. We try to provide the same character sets
  48. -- as defined in gnatcoll-email.ads.
  49. type Recipient_Kind is (Bcc, Cc, To);
  50. -- The kind of recipient, when adding a new recipient to an email.
  51. type Structure is private;
  52. -- The email structure. This type holds all the information needed to build
  53. -- a proper email.
  54. private
  55. use Ada.Containers;
  56. use Ada.Strings.Unbounded;
  57. function U
  58. (S : in String)
  59. return Unbounded_String
  60. renames To_Unbounded_String;
  61. type Attachment_Data is
  62. record
  63. Charset : Character_Set := US_ASCII;
  64. Path_To_File : Unbounded_String;
  65. end record;
  66. type Email_Data is
  67. record
  68. Address : Unbounded_String;
  69. Charset : Character_Set := US_ASCII;
  70. Name : Unbounded_String;
  71. end record;
  72. type Email_Kind is (Text,
  73. Text_With_Attachment,
  74. Text_And_HTML,
  75. Text_And_HTML_With_Attachment);
  76. type Header_Data is
  77. record
  78. Charset : Character_Set := US_ASCII;
  79. Name : Unbounded_String;
  80. Value : Unbounded_String;
  81. end record;
  82. type SMTP_Server is
  83. record
  84. Host : Unbounded_String;
  85. Port : Positive;
  86. end record;
  87. type Subject_Data is
  88. record
  89. Content : Unbounded_String;
  90. Charset : Character_Set := US_ASCII;
  91. end record;
  92. type Text_Data is
  93. record
  94. Content : Unbounded_String;
  95. Charset : Character_Set := US_ASCII;
  96. end record;
  97. -- This type is used for both text and HTML parts, so the "Text" part of
  98. -- Text_Data simply refers to the fact that both text and HTML parts are
  99. -- essentially plain text data.
  100. package Attachments_Container is new Vectors (Positive, Attachment_Data);
  101. package Custom_Headers_Container is new Vectors (Positive, Header_Data);
  102. package Email_Data_Container is new Vectors (Positive, Email_Data);
  103. package SMTP_Servers_Container is new Vectors (Positive, SMTP_Server);
  104. type Structure is
  105. record
  106. Attachment_List : Attachments_Container.Vector;
  107. Bcc_List : Email_Data_Container.Vector;
  108. Cc_List : Email_Data_Container.Vector;
  109. Composed_Message : GNATCOLL.Email.Message;
  110. Custom_Headers : Custom_Headers_Container.Vector;
  111. Email_Is_Sent : Boolean := False;
  112. From_List : Email_Data_Container.Vector;
  113. Has_Attachment : Boolean := False;
  114. Has_HTML_Part : Boolean := False;
  115. Has_Text_Part : Boolean := False;
  116. HTML_Part : Text_Data;
  117. Reply_To_List : Email_Data_Container.Vector;
  118. Sender : Email_Data;
  119. SMTP_List : SMTP_Servers_Container.Vector;
  120. Subject : Subject_Data;
  121. Text_Part : Text_Data;
  122. To_List : Email_Data_Container.Vector;
  123. Type_Of_Email : Email_Kind;
  124. end record;
  125. -- The type used to hold describe an email.
  126. -- Attachment_List:
  127. -- A list of Attachment_Data records. The validity of the Path_To_File
  128. -- component is checked when it is converted into a GNATcoll Virtual
  129. -- file.
  130. -- Bcc_List:
  131. -- A list of Email_Data records. These are collapsed into a single
  132. -- Bcc: header when Send is called, and only then do we check if each
  133. -- element is valid.
  134. -- Cc_List:
  135. -- A list of Email_Data records. These are collapsed into a single Cc:
  136. -- header when Send is called, and only then do we check if each
  137. -- element is valid.
  138. -- Composed_Message:
  139. -- The complete email in GNATCOLL.Email.Message format.
  140. -- Custom_Headers:
  141. -- A list of custom headers.
  142. -- Email_Is_Send:
  143. -- Is set to True if we succeed in sending the email.
  144. -- From_List:
  145. -- A list of Email_Data records. These are collapsed into a single
  146. -- From: header when Send is called, and only then do we check if each
  147. -- element is valid.
  148. -- Has_Attachment:
  149. -- Is set to True if an attachment is added to the email.
  150. -- Has_HTML_Part:
  151. -- Is set to True if a HTML part is added to the email.
  152. -- Has_Text_Part:
  153. -- Is set to True if a Text part is added to the email.
  154. -- HTML_Part:
  155. -- The HTML part of a multipart/alternative email.
  156. -- Reply_To_List:
  157. -- List of Email_Data records. These are collapsed into a single
  158. -- Reply-To: header when Send is called, and only then do we check if
  159. -- each element is valid.
  160. -- Sender:
  161. -- If From_List contains multiple elements, then a Sender: header is
  162. -- required as per RFC 5322 3.6.2. This header is build from the value
  163. -- of Sender.
  164. -- SMTP_List:
  165. -- List of SMTP servers to try when sending the email. The first one
  166. -- added to the list, is the first one tried. The system will keep
  167. -- going down the list, until it either succeeds in sending the email
  168. -- or until it runs out of SMTP servers to try.
  169. -- Status:
  170. -- The status code and message from the SMTP session.
  171. -- Subject:
  172. -- From this we build the Subject: header.
  173. -- Text_Part:
  174. -- The text/plain part of an email.
  175. -- To_List:
  176. -- List of Email_Data records. These are collapsed into a single To:
  177. -- header when send is called, and only then do we check if each
  178. -- element is valid.
  179. -- Type_Of_Email:
  180. -- The kind of email we're dealing with.
  181. procedure Generate_Text_And_HTML_Email
  182. (ES : in out Structure);
  183. -- Generate a text and HTML email using the GNATcoll email facilities.
  184. procedure Generate_Text_With_Attachment_Email
  185. (ES : in out Structure);
  186. -- Generate a text email with attachment(s) using the GNATcoll email
  187. -- facilities.
  188. procedure Generate_Text_Email
  189. (ES : in out Structure);
  190. -- Generate a text email using the GNATcoll email facilities.
  191. procedure Generate_Text_And_HTML_With_Attachment_Email
  192. (ES : in out Structure);
  193. -- Generate a text and HTML email with attachment(s) using the GNATcoll
  194. -- email facilities.
  195. function Get_Charset
  196. (Charset : in Character_Set)
  197. return String;
  198. -- Return the GNATcoll.Email character set string constant that is
  199. -- equivalent to the given Email.Character_Set enum.
  200. procedure Set_Type_Of_Email
  201. (ES : in out Structure);
  202. -- Figure out the kind of email ES is.
  203. end Yolk.Email;