@ -5,7 +5,7 @@ import base64
import logging
import logging
from odoo import _ , api , models , fields
from odoo import _ , api , models , fields
from odoo.exceptions import UserError
from odoo.exceptions import UserError , ValidationError
from .. import match_algorithm
from .. import match_algorithm
@ -35,11 +35,21 @@ class FetchmailServerFolder(models.Model):
algorithms . sort ( )
algorithms . sort ( )
return algorithms
return algorithms
server_id = fields . Many2one ( ' fetchmail.server ' , ' Server ' )
sequence = fields . Integer ( ' Sequence ' )
sequence = fields . Integer ( ' Sequence ' )
state = fields . Selection ( [
( ' draft ' , ' Not Confirmed ' ) ,
( ' done ' , ' Confirmed ' ) ] ,
string = ' Status ' ,
readonly = True ,
required = True ,
copy = False ,
default = ' draft ' )
path = fields . Char (
path = fields . Char (
' Path ' ,
' Path ' ,
help = " The path to your mail folder. Typically would be something like "
" ' INBOX.myfolder ' " , required = True )
required = True ,
help = " The path to your mail folder. "
" Typically would be something like ' INBOX.myfolder ' " )
model_id = fields . Many2one (
model_id = fields . Many2one (
' ir.model ' , ' Model ' , required = True ,
' ir.model ' , ' Model ' , required = True ,
help = ' The model to attach emails to ' )
help = ' The model to attach emails to ' )
@ -62,7 +72,6 @@ class FetchmailServerFolder(models.Model):
' Field (email) ' ,
' Field (email) ' ,
help = ' The field in the email used for matching. Typically '
help = ' The field in the email used for matching. Typically '
" this is ' to ' or ' from ' " )
" this is ' to ' or ' from ' " )
server_id = fields . Many2one ( ' fetchmail.server ' , ' Server ' )
delete_matching = fields . Boolean (
delete_matching = fields . Boolean (
' Delete matches ' ,
' Delete matches ' ,
help = ' Delete matched emails from server ' )
help = ' Delete matched emails from server ' )
@ -89,6 +98,20 @@ class FetchmailServerFolder(models.Model):
def get_algorithm ( self ) :
def get_algorithm ( self ) :
return self . _get_match_algorithms ( ) [ self . match_algorithm ] ( )
return self . _get_match_algorithms ( ) [ self . match_algorithm ] ( )
@api.multi
def button_confirm_folder ( self ) :
for this in self :
this . write ( { ' state ' : ' draft ' } )
if not this . active :
continue
connection = this . server_id . connect ( )
connection . select ( )
if connection . select ( this . path ) [ 0 ] != ' OK ' :
raise ValidationError (
_ ( ' Invalid folder %s ! ' ) % this . path )
connection . close ( )
this . write ( { ' state ' : ' done ' } )
@api.multi
@api.multi
def button_attach_mail_manually ( self ) :
def button_attach_mail_manually ( self ) :
self . ensure_one ( )
self . ensure_one ( )