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.

168 lines
8.1 KiB

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