1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
25
def _action_open_mail_account(self, cr, uid, data, context):
26
if data['ids'].__len__()>1:
27
raise wizard.except_wizard('Error!', 'Please select only one mail account')
28
user_obj = pooler.get_pool(cr.dbname).get('webmail.tiny.user')
29
mailbox_obj = pooler.get_pool(cr.dbname).get('webmail.mailbox')
30
server_obj = pooler.get_pool(cr.dbname).get('webmail.server')
32
mailbox_ids = mailbox_obj.search(cr, uid,[('user_id','=',uid)])
33
mailbox_obj.unlink(cr, uid, mailbox_ids)
35
for server in user_obj.browse(cr, uid, data['ids'][0]).server_conf_id:
36
mail_acc = server_obj.browse(cr, uid, server.id)
37
parent_accid = mailbox_obj.create(cr, uid, {'name':mail_acc.name, 'user_id':uid })
38
if mail_acc.iserver_type=='imap':
39
folders = mailbox_obj.select(cr, uid, data['ids'], context, mail_acc)
40
for folder in folders:
41
value = folder.split("\"")
46
mailbox_obj.create(cr, uid, {'name':name, 'parent_id':parent_accid, 'user_id':uid })
47
elif mail_acc.iconn_type=='pop3':
48
mailbox_obj.create(cr, uid, {'name':'Inbox', 'parent_id':parent_accid, 'user_id':uid })
50
'domain': "[('parent_id','=',False),('user_id','=',%d)]" % (uid),
51
'name': 'Mail Account',
53
'res_model': 'webmail.mailbox',
56
'type': 'ir.actions.act_window'
59
class wizard_mail_account(wizard.interface):
64
'result': {'type': 'action', 'action': _action_open_mail_account, 'state':'end'}
68
wizard_mail_account('webmail.mail.account')
69
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: