<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import time

from imaplib import IMAP4
from imaplib import IMAP4_SSL
from poplib import POP3
from poplib import POP3_SSL

import netsvc
from osv import osv, fields

logger = netsvc.Logger()


class email_server(osv.osv):

    _name = 'email.server'
    _description = "POP/IMAP Server"

    _columns = {
        'name':fields.char('Name', size=256, required=True, readonly=False),
        'active':fields.boolean('Active', required=False),
        'state':fields.selection([
            ('draft', 'Not Confirmed'),
            ('waiting', 'Waiting for Verification'),
            ('done', 'Confirmed'),
        ], 'State', select=True, readonly=True),
        'server' : fields.char('Server', size=256, required=True, readonly=True, states={'draft':[('readonly', False)]}),
        'port' : fields.integer('Port', required=True, readonly=True, states={'draft':[('readonly', False)]}),
        'type':fields.selection([
            ('pop', 'POP Server'),
            ('imap', 'IMAP Server'),
        ], 'Server Type', select=True, readonly=False),
        'is_ssl':fields.boolean('SSL ?', required=False),
        'attach':fields.boolean('Add Attachments ?', required=False, help="Fetches mail with attachments if true."),
        'date': fields.date('Date', readonly=True, states={'draft':[('readonly', False)]}),
        'user' : fields.char('<NAME>', size=256, required=True, readonly=True, states={'draft':[('readonly', False)]}),
        'password' : fields.char('Password', size=1024, invisible=True, required=True, readonly=True, states={'draft':[('readonly', False)]}),
        'note': fields.text('Description'),
        'action_id':fields.many2one('ir.actions.server', 'Email Server Action', required=False, domain="[('state','=','email')]", help="An Email Server Action. It will be run whenever an e-mail is fetched from server."),
        'object_id': fields.many2one('ir.model', "Model", required=True, help="OpenObject Model. Generates a record of this model.\nSelect Object with message_new attrbutes."),
        'priority': fields.integer('Server Priority', readonly=True, states={'draft':[('readonly', False)]}, help="Priority between 0 to 10, select define the order of Processing"),
        'user_id':fields.many2one('res.users', 'User', required=False),
        'message_ids': fields.one2many('mailgate.message', 'server_id', 'Messages', readonly=True),
    }
    _defaults = {
        'state': lambda *a: "draft",
        'active': lambda *a: True,
        'priority': lambda *a: 5,
        'date': lambda *a: time.strftime('%Y-%m-%d'),
        'user_id': lambda self, cr, uid, ctx: uid,
    }

    def check_duplicate(self, cr, uid, ids, context=None):
        # RFC *-* Why this limitation? why not in SQL constraint?
        vals = self.read(cr, uid, ids, ['user', 'password'], context=context)[0]
        cr.execute("select count(id) from email_server where user=%s and password=%s", (vals['user'], vals['password']))
        res = cr.fetchone()
        if res:
            if res[0] > 1:
                return False
        return True

    def check_model(self, cr, uid, ids, context = None):
        if context is None:
            context = {}
        current_rec = self.read(cr, uid, ids, context)[0]
        if current_rec:
            model = self.pool.get(current_rec.get('object_id')[1])
            if hasattr(model, 'message_new'):
                return True
        return False

    _constraints = [
        (check_duplicate, 'Warning! Can\'t have duplicate server configuration!', ['user', 'password']),
        (check_model, 'Warning! Record for selected Model can not be created\nPlease choose valid Model', ['object_id'])
    ]

    def onchange_server_type(self, cr, uid, ids, server_type=False, ssl=False):
        port = 0
        if server_type == 'pop':
            port = ssl and 995 or 110
        elif server_type == 'imap':
            port = ssl and 993 or 143

        return {'value':{'port':port}}<commit_msg>[Fix] fetchmail: fix Fetchmail Services<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import time

from imaplib import IMAP4
from imaplib import IMAP4_SSL
from poplib import POP3
from poplib import POP3_SSL

import netsvc
from osv import osv, fields

logger = netsvc.Logger()


class email_server(osv.osv):

    _name = 'email.server'
    _description = "POP/IMAP Server"

    _columns = {
        'name':fields.char('Name', size=256, required=True, readonly=False),
        'active':fields.boolean('Active', required=False),
        'state':fields.selection([
            ('draft', 'Not Confirmed'),
            ('waiting', 'Waiting for Verification'),
            ('done', 'Confirmed'),
        ], 'State', select=True, readonly=True),
        'server' : fields.char('Server', size=256, required=True, readonly=True, states={'draft':[('readonly', False)]}),
        'port' : fields.integer('Port', required=True, readonly=True, states={'draft':[('readonly', False)]}),
        'type':fields.selection([
            ('pop', 'POP Server'),
            ('imap', 'IMAP Server'),
        ], 'Server Type', select=True, readonly=False),
        'is_ssl':fields.boolean('SSL ?', required=False),
        'attach':fields.boolean('Add Attachments ?', required=False, help="Fetches mail with attachments if true."),
        'date': fields.date('Date', readonly=True, states={'draft':[('readonly', False)]}),
        'user' : fields.char('User Name', size=256, required=True, readonly=True, states={'draft':[('readonly', False)]}),
        'password' : fields.char('Password', size=1024, invisible=True, required=True, readonly=True, states={'draft':[('readonly', False)]}),
        'note': fields.text('Description'),
        'action_id':fields.many2one('ir.actions.server', 'Email Server Action', required=False, domain="[('state','=','email')]", help="An Email Server Action. It will be run whenever an e-mail is fetched from server."),
        'object_id': fields.many2one('ir.model', "Model", required=True, help="OpenObject Model. Generates a record of this model.\nSelect Object with message_new attrbutes."),
        'priority': fields.integer('Server Priority', readonly=True, states={'draft':[('readonly', False)]}, help="Priority between 0 to 10, select define the order of Processing"),
        'user_id':fields.many2one('res.users', 'User', required=False),
        'message_ids': fields.one2many('mailgate.message', 'server_id', 'Messages', readonly=True),
    }
    _defaults = {
        'state': lambda *a: "draft",
        'active': lambda *a: True,
        'priority': lambda *a: 5,
        'date': lambda *a: time.strftime('%Y-%m-%d'),
        'user_id': lambda self, cr, uid, ctx: uid,
    }

    def check_duplicate(self, cr, uid, ids, context=None):
        # RFC *-* Why this limitation? why not in SQL constraint?
        vals = self.read(cr, uid, ids, ['user', 'password'], context=context)[0]
        cr.execute("select count(id) from email_server where user=%s and password=%s", (vals['user'], vals['password']))
        res = cr.fetchone()
        if res:
            if res[0] > 1:
                return False
        return True

    def check_model(self, cr, uid, ids, context = None):
        if context is None:
            context = {}
        current_rec = self.read(cr, uid, ids, context)
        if current_rec:
            current_rec = current_rec[0]
            model_name = self.pool.get('ir.model').browse(cr, uid, current_rec.get('object_id')[0]).model
            model = self.pool.get(model_name)
            if hasattr(model, 'message_new'):
                return True
        return False

    _constraints = [
        (check_duplicate, 'Warning! Can\'t have duplicate server configuration!', ['user', 'password']),
        (check_model, 'Warning! Record for selected Model can not be created\nPlease choose valid Model', ['object_id'])
    ]

    def onchange_server_type(self, cr, uid, ids, server_type=False, ssl=False):
        port = 0
        if server_type == 'pop':
            port = ssl and 995 or 110
        elif server_type == 'imap':
            port = ssl and 993 or 143

        return {'value':{'port':port}}
{'fraction_non_alphanumeric': 0.17298907646474676, 'fraction_numerical': 0.010526315789473684, 'mean_word_length': 3.3353422298751614, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1527928', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2823, 'n_words': 884}