Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thomas Gambier
erp5
Commits
c72c3740
Commit
c72c3740
authored
Oct 29, 2014
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_email_reader: use transaction cache instead of read-only transaction cache
parent
22887cde
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
138 deletions
+64
-138
bt5/erp5_email_reader/DocumentTemplateItem/portal_components/document.erp5.EmailReader.py
...mplateItem/portal_components/document.erp5.EmailReader.py
+21
-41
bt5/erp5_email_reader/DocumentTemplateItem/portal_components/document.erp5.EmailReader.xml
...plateItem/portal_components/document.erp5.EmailReader.xml
+43
-97
No files found.
bt5/erp5_email_reader/DocumentTemplateItem/portal_components/document.erp5.EmailReader.py
View file @
c72c3740
...
@@ -32,7 +32,7 @@ from Products.CMFCore.utils import getToolByName
...
@@ -32,7 +32,7 @@ from Products.CMFCore.utils import getToolByName
from
Products.ERP5Type
import
Permissions
,
PropertySheet
from
Products.ERP5Type
import
Permissions
,
PropertySheet
from
Products.ERP5.Document.ExternalSource
import
ExternalSource
from
Products.ERP5.Document.ExternalSource
import
ExternalSource
from
Products.ERP5Type.XMLObject
import
XMLObject
from
Products.ERP5Type.XMLObject
import
XMLObject
from
Products.ERP5Type.Cache
import
getReadOnlyTransactionCache
from
Products.ERP5Type.Cache
import
transactional_cached
# IMAP imports
# IMAP imports
import
imaplib
import
imaplib
...
@@ -215,7 +215,7 @@ class IMAPServer(IMAPSServer):
...
@@ -215,7 +215,7 @@ class IMAPServer(IMAPSServer):
are closed and logged out.
are closed and logged out.
"""
"""
def
__init__
(
self
,
host
,
user
,
password
,
port
=
143
):
def
__init__
(
self
,
host
,
user
,
password
,
port
=
143
):
return
IMAPSServer
.
__init__
(
self
,
host
,
user
,
password
,
port
=
port
)
IMAPSServer
.
__init__
(
self
,
host
,
user
,
password
,
port
=
port
)
class
POPSServer
(
MailServer
):
class
POPSServer
(
MailServer
):
"""
"""
...
@@ -227,7 +227,7 @@ class POPSServer(MailServer):
...
@@ -227,7 +227,7 @@ class POPSServer(MailServer):
class
POPServer
(
POPSServer
):
class
POPServer
(
POPSServer
):
def
__init__
(
self
,
host
,
user
,
password
,
port
=
143
):
def
__init__
(
self
,
host
,
user
,
password
,
port
=
143
):
return
POPSServer
.
__init__
(
self
,
host
,
user
,
password
,
port
=
port
)
POPSServer
.
__init__
(
self
,
host
,
user
,
password
,
port
=
port
)
class
EmailReader
(
ExternalSource
):
class
EmailReader
(
ExternalSource
):
...
@@ -437,28 +437,17 @@ class EmailReader(ExternalSource):
...
@@ -437,28 +437,17 @@ class EmailReader(ExternalSource):
return
"%s-%s"
%
(
message_folder
.
replace
(
'/'
,
'.'
),
uid
)
# Can this be configurable, based on what ? date?
return
"%s-%s"
%
(
message_folder
.
replace
(
'/'
,
'.'
),
uid
)
# Can this be configurable, based on what ? date?
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getMessageFolderList'
)
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getMessageFolderList'
)
@
transactional_cached
()
def
getMessageFolderList
(
self
):
def
getMessageFolderList
(
self
):
"""
"""
Returns the list of folders of the current server
Returns the list of folders of the current server
XXX Add read only transaction cache
XXX Add read only transaction cache
"""
"""
cache
=
getReadOnlyTransactionCache
()
if
cache
is
not
None
:
key
=
(
'getMessageFolderList'
,
self
)
try
:
return
cache
[
key
]
except
KeyError
:
pass
server
=
self
.
_getMailServer
()
server
=
self
.
_getMailServer
()
if
server
is
None
:
return
()
return
()
if
server
is
None
else
server
.
getMessageFolderList
()
result
=
server
.
getMessageFolderList
()
if
cache
is
not
None
:
cache
[
key
]
=
result
return
result
### Implementation - Private methods
### Implementation - Private methods
@
transactional_cached
()
def
_getMailServer
(
self
):
def
_getMailServer
(
self
):
"""
"""
A private method to retrieve a mail server
A private method to retrieve a mail server
...
@@ -468,32 +457,23 @@ class EmailReader(ExternalSource):
...
@@ -468,32 +457,23 @@ class EmailReader(ExternalSource):
break things. An interactor is required to clear
break things. An interactor is required to clear
the variable
the variable
"""
"""
cache
=
getReadOnlyTransactionCache
()
if
cache
is
not
None
:
key
=
(
'_getMailServer'
,
self
)
try
:
return
cache
[
key
]
except
KeyError
:
pass
# No server defined
# No server defined
if
not
self
.
getURLServer
():
return
None
server_url
=
self
.
getURLServer
()
if
not
server_url
:
return
# XXX - Here we need to add a switch (POP vs. IMAP vs. IMAPS etc.)
# XXX - Here we need to add a switch (POP vs. IMAP vs. IMAPS etc.)
url_protocol
=
self
.
getUrlProtocol
(
'imaps'
)
# Default to IMAP
url_protocol
=
self
.
getUrlProtocol
(
'imaps'
)
# Default to IMAP
if
url_protocol
==
'imaps'
:
if
url_protocol
==
'imaps'
:
result
=
IMAPSServer
(
self
.
getURLServer
(),
self
.
getUserId
(),
self
.
getPassword
(),
port
=
self
.
getURLPort
())
server_class
=
IMAPSServer
elif
url_protocol
==
'imap'
:
elif
url_protocol
==
'imap'
:
result
=
IMAPServer
(
self
.
getURLServer
(),
self
.
getUserId
(),
self
.
getPassword
(),
port
=
self
.
getURLPort
())
server_class
=
IMAPServer
elif
url_protocol
==
'pops'
:
elif
url_protocol
==
'pops'
:
result
=
POPSServer
(
self
.
getURLServer
(),
self
.
getUserId
(),
self
.
getPassword
(),
port
=
self
.
getURLPort
())
server_class
=
POPSServer
elif
url_protocol
==
'pop'
:
elif
url_protocol
==
'pop'
:
result
=
POPServer
(
self
.
getURLServer
(),
self
.
getUserId
(),
self
.
getPassword
(),
port
=
self
.
getURLPort
())
server_class
=
POPServer
else
:
else
:
raise
NotImplementedError
raise
NotImplementedError
if
cache
is
not
None
:
return
server_class
(
server_url
,
self
.
getUserId
(),
self
.
getPassword
(),
cache
[
key
]
=
result
port
=
self
.
getURLPort
())
return
result
bt5/erp5_email_reader/DocumentTemplateItem/portal_components/document.erp5.EmailReader.xml
View file @
c72c3740
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment