You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
8.8 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Nicolas Bessi
  5. # Copyright 2012 Camptocamp SA
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program 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 Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from osv import fields
  22. from osv import osv
  23. from server_environment import serv_config
  24. class IrMail(osv.osv):
  25. _inherit = "ir.mail_server"
  26. def _get_smtp_conf(self, cursor, uid, ids, name, args, context=None):
  27. """
  28. Return configuration
  29. """
  30. res = {}
  31. for mail_server in self.browse(cursor, uid, ids):
  32. global_section_name = 'outgoing_mail'
  33. # default vals
  34. config_vals = {'smtp_port': 587}
  35. if serv_config.has_section(global_section_name):
  36. config_vals.update((serv_config.items(global_section_name)))
  37. custom_section_name = '.'.join(
  38. (global_section_name, mail_server.name))
  39. if serv_config.has_section(custom_section_name):
  40. config_vals.update(serv_config.items(custom_section_name))
  41. if config_vals.get('smtp_port'):
  42. config_vals['smtp_port'] = int(config_vals['smtp_port'])
  43. res[mail_server.id] = config_vals
  44. return res
  45. _columns = {
  46. 'smtp_host': fields.function(_get_smtp_conf,
  47. method=True,
  48. string='SMTP Server',
  49. type="char",
  50. multi='outgoing_mail_config',
  51. size=128),
  52. 'smtp_port': fields.function(_get_smtp_conf,
  53. method=True,
  54. string='SMTP Port',
  55. type="integer",
  56. multi='outgoing_mail_config',
  57. help="SMTP Port. Usually 465 for SSL, "
  58. "and 25 or 587 for other cases.",
  59. size=5),
  60. 'smtp_user': fields.function(_get_smtp_conf,
  61. method=True,
  62. string='Username',
  63. type="char",
  64. multi='outgoing_mail_config',
  65. help="Optional username for SMTP "
  66. "authentication",
  67. size=64),
  68. 'smtp_pass': fields.function(_get_smtp_conf,
  69. method=True,
  70. string='Password',
  71. type="char",
  72. multi='outgoing_mail_config',
  73. help="Optional password for SMTP "
  74. "authentication",
  75. size=64),
  76. 'smtp_encryption': fields.function(
  77. _get_smtp_conf,
  78. method=True,
  79. string='smtp_encryption',
  80. type="char",
  81. multi='outgoing_mail_config',
  82. help="Choose the connection encryption scheme:\n"
  83. "- none: SMTP sessions are done in cleartext.\n"
  84. "- starttls: TLS encryption is requested at start of SMTP session "
  85. "(Recommended)\n"
  86. "- ssl: SMTP sessions are encrypted with SSL/TLS through a "
  87. "dedicated port (default: 465)",
  88. size=64),
  89. }
  90. IrMail()
  91. class FetchmailServer(osv.osv):
  92. """Incoming POP/IMAP mail server account"""
  93. _inherit = 'fetchmail.server'
  94. def _get_incom_conf(self, cursor, uid, ids, name, args, context=None):
  95. """
  96. Return configuration
  97. """
  98. res = {}
  99. for fetchmail in self.browse(cursor, uid, ids):
  100. global_section_name = 'incoming_mail'
  101. key_types = {
  102. 'port': int,
  103. 'is_ssl': lambda a: bool(int(a)),
  104. 'attach': lambda a: bool(int(a)),
  105. 'original': lambda a: bool(int(a)),
  106. }
  107. # default vals
  108. config_vals = {'port': 993,
  109. 'is_ssl': 0,
  110. 'attach': 0,
  111. 'original': 0}
  112. if serv_config.has_section(global_section_name):
  113. config_vals.update(serv_config.items(global_section_name))
  114. custom_section_name = '.'.join(
  115. (global_section_name, fetchmail.name))
  116. if serv_config.has_section(custom_section_name):
  117. config_vals.update(serv_config.items(custom_section_name))
  118. for key, to_type in key_types.iteritems():
  119. if config_vals.get(key):
  120. config_vals[key] = to_type(config_vals[key])
  121. res[fetchmail.id] = config_vals
  122. return res
  123. _columns = {
  124. 'server': fields.function(_get_incom_conf,
  125. method=True,
  126. string='Server',
  127. type="char",
  128. multi='income_mail_config',
  129. size=256,
  130. help="Hostname or IP of the mail server"),
  131. 'port': fields.function(_get_incom_conf,
  132. method=True,
  133. string='Port',
  134. type="integer",
  135. multi='income_mail_config',
  136. help="Hostname or IP of the mail server"),
  137. 'type': fields.function(_get_incom_conf,
  138. method=True,
  139. string='Type',
  140. type="char",
  141. multi='income_mail_config',
  142. size=64,
  143. help="pop, imap, local"),
  144. 'is_ssl': fields.function(_get_incom_conf,
  145. method=True,
  146. string='Is SSL',
  147. type="boolean",
  148. multi='income_mail_config',
  149. help='Connections are encrypted with '
  150. 'SSL/TLS through a dedicated port (default: '
  151. 'IMAPS=993, POP3S=995)'),
  152. 'attach': fields.function(_get_incom_conf,
  153. method=True,
  154. string='Keep Attachments',
  155. type="boolean",
  156. multi='income_mail_config',
  157. help="Whether attachments should be "
  158. "downloaded. If not enabled, incoming "
  159. "emails will be stripped of any attachments "
  160. "before being processed"),
  161. 'original': fields.function(_get_incom_conf,
  162. method=True,
  163. string='Keep Original',
  164. type="boolean",
  165. multi='income_mail_config',
  166. help="Whether a full original copy of "
  167. "each email should be kept for reference"
  168. "and attached to each processed message. "
  169. "This will usually double the size of "
  170. "your message database."),
  171. 'user': fields.function(_get_incom_conf,
  172. method=True,
  173. string='Username',
  174. type="char",
  175. multi='income_mail_config',
  176. size=64),
  177. 'password': fields.function(_get_incom_conf,
  178. method=True,
  179. string='password',
  180. type="char",
  181. multi='income_mail_config',
  182. size=64)}
  183. FetchmailServer()