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.

184 lines
8.7 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((global_section_name, mail_server.name))
  38. if serv_config.has_section(custom_section_name):
  39. config_vals.update(serv_config.items(custom_section_name))
  40. if config_vals.get('smtp_port'):
  41. config_vals['smtp_port'] = int(config_vals['smtp_port'])
  42. res[mail_server.id] = config_vals
  43. return res
  44. _columns = {
  45. 'smtp_host': fields.function(_get_smtp_conf,
  46. method=True,
  47. string='SMTP Server',
  48. type="char",
  49. multi='outgoing_mail_config',
  50. size=128),
  51. 'smtp_port': fields.function(_get_smtp_conf,
  52. method=True,
  53. string='SMTP Port',
  54. type="integer",
  55. multi='outgoing_mail_config',
  56. help="SMTP Port. Usually 465 for SSL, and 25 or 587 for other cases.",
  57. size=5),
  58. 'smtp_user': fields.function(_get_smtp_conf,
  59. method=True,
  60. string='Username',
  61. type="char",
  62. multi='outgoing_mail_config',
  63. help="Optional username for SMTP authentication",
  64. size=64),
  65. 'smtp_pass': fields.function(_get_smtp_conf,
  66. method=True,
  67. string='Password',
  68. type="char",
  69. multi='outgoing_mail_config',
  70. help="Optional password for SMTP authentication",
  71. size=64),
  72. 'smtp_encryption' :fields.function(_get_smtp_conf,
  73. method=True,
  74. string='smtp_encryption',
  75. type="char",
  76. multi='outgoing_mail_config',
  77. help="Choose the connection encryption scheme:\n"
  78. "- none: SMTP sessions are done in cleartext.\n"
  79. "- starttls: TLS encryption is requested at start of SMTP session (Recommended)\n"
  80. "- ssl: SMTP sessions are encrypted with SSL/TLS through a dedicated port (default: 465)",
  81. size=64)}
  82. IrMail()
  83. class FetchmailServer(osv.osv):
  84. """Incoming POP/IMAP mail server account"""
  85. _inherit = 'fetchmail.server'
  86. def _get_incom_conf(self, cursor, uid, ids, name, args, context=None):
  87. """
  88. Return configuration
  89. """
  90. res = {}
  91. for fetchmail in self.browse(cursor, uid, ids):
  92. global_section_name = 'incoming_mail'
  93. key_types = {'port': int,
  94. 'is_ssl': lambda a: bool(int(a)),
  95. 'attach': lambda a: bool(int(a)),
  96. 'original': lambda a: bool(int(a)),}
  97. # default vals
  98. config_vals = {'port': 993,
  99. 'is_ssl': 0,
  100. 'attach': 0,
  101. 'original': 0}
  102. if serv_config.has_section(global_section_name):
  103. config_vals.update(serv_config.items(global_section_name))
  104. custom_section_name = '.'.join((global_section_name, fetchmail.name))
  105. if serv_config.has_section(custom_section_name):
  106. config_vals.update(serv_config.items(custom_section_name))
  107. for key, to_type in key_types.iteritems():
  108. if config_vals.get(key):
  109. config_vals[key] = to_type(config_vals[key])
  110. res[fetchmail.id] = config_vals
  111. return res
  112. _columns = {
  113. 'server': fields.function(_get_incom_conf,
  114. method=True,
  115. string='Server',
  116. type="char",
  117. multi='income_mail_config',
  118. size=256, help="Hostname or IP of the mail server"),
  119. 'port': fields.function(_get_incom_conf,
  120. method=True,
  121. string='Port',
  122. type="integer",
  123. multi='income_mail_config',
  124. help="Hostname or IP of the mail server"),
  125. 'type': fields.function(_get_incom_conf,
  126. method=True,
  127. string='Type',
  128. type="char",
  129. multi='income_mail_config',
  130. size=64,
  131. help="pop, imap, local"),
  132. 'is_ssl': fields.function(_get_incom_conf,
  133. method=True,
  134. string='Is SSL',
  135. type="boolean",
  136. multi='income_mail_config',
  137. help='Connections are encrypted with SSL/TLS through'
  138. ' a dedicated port (default: IMAPS=993, POP3S=995)'),
  139. 'attach': fields.function(_get_incom_conf,
  140. method=True,
  141. string='Keep Attachments',
  142. type="boolean",
  143. multi='income_mail_config',
  144. help="Whether attachments should be downloaded. "
  145. "If not enabled, incoming emails will be stripped of any attachments before being processed"),
  146. 'original': fields.function(_get_incom_conf,
  147. method=True,
  148. string='Keep Original',
  149. type="boolean",
  150. multi='income_mail_config',
  151. help="Whether a full original copy of each email should be kept for reference"
  152. "and attached to each processed message. This will usually double the size of your message database."),
  153. 'user': fields.function(_get_incom_conf,
  154. method=True,
  155. string='Username',
  156. type="char",
  157. multi='income_mail_config',
  158. size=64),
  159. 'password': fields.function(_get_incom_conf,
  160. method=True,
  161. string='password',
  162. type="char",
  163. multi='income_mail_config',
  164. size=64)}
  165. FetchmailServer()