fetchmail.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # BizzAppDev
  5. # Copyright (C) 2015-TODAY bizzappdev(<http://www.bizzappdev.com>).
  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. import logging
  22. from openerp import _, api, models
  23. from openerp.osv import osv
  24. from openerp.tools import config
  25. _logger = logging.getLogger(__name__)
  26. class fetchmail_server(models.Model):
  27. _inherit = 'fetchmail.server'
  28. def get_mode(self, dbname):
  29. mode = config.get('develop', {}).get(
  30. dbname, False) and 'develop' or False
  31. mode = not mode and config.get('test', {}).get(
  32. dbname, False) and 'test' or mode
  33. return mode
  34. def button_confirm_login(self, cr, uid, ids, context=None):
  35. if context is None:
  36. context = {}
  37. if self.get_mode(cr.dbname):
  38. raise osv.except_osv(
  39. _("OpenERP Mode"),
  40. _("You Can not Confirm & Test Because OpenERP is in %s mode.") % self.get_mode(cr.dbname).upper())
  41. return super(fetchmail_server, self).button_confirm_login(cr, uid, ids, context=context)
  42. @api.cr_uid_ids_context
  43. def connect(self, cr, uid, server_id, context=None):
  44. if isinstance(server_id, (list, tuple)):
  45. server_id = server_id[0]
  46. if self.get_mode(cr.dbname):
  47. raise osv.except_osv(
  48. _("OpenERP Mode"),
  49. _("Can not Connect to server because Openerp is in %s mode.") % self.get_mode(cr.dbname).upper())
  50. return super(fetchmail_server, self).connect(cr, uid, server_id=server_id, context=context)
  51. def fetch_mail(self, cr, uid, ids, context=None):
  52. if self.get_mode(cr.dbname):
  53. raise osv.except_osv(
  54. _("OpenERP Mode"),
  55. _("Can not fetchmail because Openerp is in %s mode.") % self.get_mode(cr.dbname).upper())
  56. return super(fetchmail_server, self).fetch_mail(cr, uid, ids=ids, context=context)
  57. fetchmail_server()
  58. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: