~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to webmail/wizard/wizard_mail_account.py

  • Committer: Fabien Pinckaers
  • Date: 2008-11-12 06:43:12 UTC
  • Revision ID: fp@tinyerp.com-20081112064312-fp85io97i1e95tuz
moved

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution   
 
5
#    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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/>.
 
20
#
 
21
##############################################################################
 
22
import wizard
 
23
import pooler
 
24
 
 
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')
 
31
    
 
32
    mailbox_ids = mailbox_obj.search(cr, uid,[('user_id','=',uid)])
 
33
    mailbox_obj.unlink(cr, uid, mailbox_ids)
 
34
    
 
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("\"")
 
42
                    if value.__len__()>0:
 
43
                        name = value[3]
 
44
                    else:
 
45
                        name = folder
 
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 })
 
49
    return  {
 
50
        'domain': "[('parent_id','=',False),('user_id','=',%d)]" % (uid),
 
51
        'name': 'Mail Account',
 
52
        'view_type': 'tree',
 
53
        'res_model': 'webmail.mailbox',
 
54
        'view_id': False,
 
55
        'context': "{}",
 
56
        'type': 'ir.actions.act_window'
 
57
    }
 
58
 
 
59
class wizard_mail_account(wizard.interface):
 
60
   
 
61
    states = {
 
62
        'init': {
 
63
            'actions': [],
 
64
            'result': {'type': 'action', 'action': _action_open_mail_account, 'state':'end'}
 
65
        },        
 
66
    }
 
67
    
 
68
wizard_mail_account('webmail.mail.account')
 
69
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
70