Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubes
email
Commits
2ea3368b341d
Commit
404f7435
authored
Dec 09, 2009
by
Carlos
Browse files
changes needed to work with cw 3.6 api
parent
19fc50ba7cc1
Changes
5
Hide whitespace changes
Inline
Side-by-side
entities.py
View file @
2ea3368b
...
...
@@ -104,7 +104,7 @@ class EmailPart(AnyEntity):
def
dc_title
(
self
):
return
'%s (%s %s)'
%
(
self
.
email
.
subject
,
self
.
req
.
_
(
'part'
),
self
.
ordernum
)
self
.
_cw
.
_
(
'part'
),
self
.
ordernum
)
@
property
def
email
(
self
):
...
...
hooks.py
View file @
2ea3368b
...
...
@@ -14,7 +14,7 @@ from logilab.mtconverter import TransformError
from
cubicweb
import
UnknownEid
,
typed_eid
from
cubicweb.mail
import
parse_message_id
from
cubicweb.selectors
import
entity_
implements
from
cubicweb.selectors
import
implements
from
cubicweb.server
import
hook
...
...
@@ -42,8 +42,8 @@ class ExtractEmailInformation(hook.Operation):
except
UnknownEid
:
self
.
error
(
'email %s is referencing an unknown eid %s'
,
email
.
messageid
,
origeid
)
return
if
origetype
in
self
.
s
chema
.
r
schema
(
'comments'
)
.
objects
(
'Comment'
):
return
if
origetype
in
self
.
s
ession
.
vreg
.
schema
[
'comments'
]
.
objects
(
'Comment'
):
try
:
part
=
email
.
parts_in_order
(
prefered_mime_type
=
'text/plain'
)[
0
]
except
IndexError
:
...
...
@@ -89,13 +89,13 @@ class AddEmailHook(hook.Hook):
"""an email has been added, check if associated content should be created
"""
__regid__
=
'extractmailcontent'
__select__
=
hook
.
Hook
.
__select__
&
entity_
implements
(
'Email'
)
__select__
=
hook
.
Hook
.
__select__
&
implements
(
'Email'
)
events
=
(
'after_add_entity'
,)
def
__call__
(
self
):
if
'comments'
in
self
.
_cw
.
repo
.
schema
:
for
msgid
in
self
.
entity
.
references
():
info
=
parse_message_id
(
msgid
,
self
.
config
.
appid
)
info
=
parse_message_id
(
msgid
,
self
.
_cw
.
vreg
.
config
.
appid
)
self
.
info
(
'extracted information from message id %s: %s'
,
msgid
,
info
)
if
info
:
...
...
test/unittest_hooks.py
View file @
2ea3368b
...
...
@@ -4,7 +4,7 @@ from StringIO import StringIO
from
logilab.common.testlib
import
unittest_main
from
cubicweb.devtools.
app
test
import
EnvBased
TC
from
cubicweb.devtools.test
lib
import
CubicWeb
TC
from
cubicweb.common.mail
import
construct_message_id
MSG
=
u
'''From sthenault@free.fr Tue Jan 23 15:21:10 2007
...
...
@@ -39,11 +39,11 @@ Content-Length: 122
Lines: 2
'''
class
ChangeStateHooksTC
(
EnvBased
TC
):
class
ChangeStateHooksTC
(
CubicWeb
TC
):
def
setup_database
(
self
):
self
.
add
_entity
(
'BlogEntry'
,
title
=
u
"une news !"
,
content
=
u
"cubicweb c'est beau"
)
self
.
add
_entity
(
'EmailAddress'
,
address
=
u
'devel@logilab.fr'
,
alias
=
u
'devel'
)
self
.
request
().
create
_entity
(
'BlogEntry'
,
title
=
u
"une news !"
,
content
=
u
"cubicweb c'est beau"
)
self
.
request
().
create
_entity
(
'EmailAddress'
,
address
=
u
'devel@logilab.fr'
,
alias
=
u
'devel'
)
self
.
msg
=
MSG
%
(
self
.
vreg
.
config
.
appid
,
gethostname
())
...
...
@@ -140,15 +140,15 @@ hop
from
cubes.email.mboximport
import
MBOXImporter
class
ReplyCommentHooksTC
(
EnvBased
TC
):
class
ReplyCommentHooksTC
(
CubicWeb
TC
):
def
setup_database
(
self
):
self
.
b
=
self
.
add
_entity
(
'BlogEntry'
,
title
=
u
"une news !"
,
content
=
u
"cubicweb c'est beau"
)
e
=
self
.
add
_entity
(
'EmailAddress'
,
address
=
u
'sylvain.thenault@logilab.fr'
,
alias
=
u
'syt'
)
self
.
b
=
self
.
request
().
create
_entity
(
'BlogEntry'
,
title
=
u
"une news !"
,
content
=
u
"cubicweb c'est beau"
)
e
=
self
.
request
().
create
_entity
(
'EmailAddress'
,
address
=
u
'sylvain.thenault@logilab.fr'
,
alias
=
u
'syt'
)
self
.
execute
(
'SET X use_email E WHERE X login "anon", E eid %(e)s'
,
{
'e'
:
e
.
eid
})
def
test_comment_created
(
self
):
mi
=
MBOXImporter
(
self
.
env
.
cnx
)
mi
=
MBOXImporter
(
self
.
cnx
)
msg
=
open
(
'data/reply.mbox'
,
'rb'
).
read
()
%
\
construct_message_id
(
self
.
vreg
.
config
.
appid
,
self
.
b
.
eid
,
False
)
mi
.
import_mbox_stream
(
StringIO
(
msg
))
...
...
test/unittest_mboximport.py
View file @
2ea3368b
...
...
@@ -4,12 +4,12 @@ from StringIO import StringIO
from
logilab.common.testlib
import
TestCase
,
unittest_main
from
cubicweb.devtools.
app
test
import
EnvBased
TC
from
cubicweb.devtools.test
lib
import
CubicWeb
TC
from
cubes.email.mboximport
import
MBOXImporter
class
MBOXImporterTC
(
EnvBased
TC
):
class
MBOXImporterTC
(
CubicWeb
TC
):
def
test_all
(
self
):
mi
=
MBOXImporter
(
self
.
env
.
cnx
)
...
...
views/email.py
View file @
2ea3368b
...
...
@@ -35,7 +35,7 @@ def formated_sender(email):
message
=
email
.
umessage_headers
()
if
message
:
return
xml_escape
(
message
.
get
(
'From'
))
return
email
.
req
.
_
(
'unknown sender'
)
return
email
.
_cw
.
_
(
'unknown sender'
)
class
EmailPrimaryView
(
primary
.
PrimaryView
):
__select__
=
implements
(
'Email'
)
...
...
@@ -43,21 +43,21 @@ class EmailPrimaryView(primary.PrimaryView):
def
render_entity_attributes
(
self
,
entity
):
self
.
w
(
u
'<div class="emailheader"><table>'
)
self
.
w
(
u
'<tr><td>%s</td><td>%s</td></tr>'
%
(
self
.
req
.
_
(
'From'
),
formated_sender
(
entity
)))
(
self
.
_cw
.
_
(
'From'
),
formated_sender
(
entity
)))
self
.
w
(
u
'<tr><td>%s</td><td>%s</td></tr>'
%
(
self
.
req
.
_
(
'To'
),
', '
.
join
(
ea
.
view
(
'oneline'
)
for
ea
in
entity
.
recipients
)))
(
self
.
_cw
.
_
(
'To'
),
', '
.
join
(
ea
.
view
(
'oneline'
)
for
ea
in
entity
.
recipients
)))
if
entity
.
cc
:
self
.
w
(
u
'<tr><td>%s</td><td>%s</td></tr>'
%
(
self
.
req
.
_
(
'CC'
),
', '
.
join
(
ea
.
view
(
'oneline'
)
for
ea
in
entity
.
cc
)))
(
self
.
_cw
.
_
(
'CC'
),
', '
.
join
(
ea
.
view
(
'oneline'
)
for
ea
in
entity
.
cc
)))
self
.
w
(
u
'<tr><td>%s</td><td>%s</td></tr>'
%
(
self
.
req
.
_
(
'Date'
),
self
.
format_date
(
entity
.
date
,
time
=
True
)))
(
self
.
_cw
.
_
(
'Date'
),
self
.
_cw
.
format_date
(
entity
.
date
,
time
=
True
)))
self
.
w
(
u
'<tr><td>%s</td><td>%s</td></tr>'
%
(
self
.
req
.
_
(
'Subject'
),
xml_escape
(
entity
.
subject
)))
(
self
.
_cw
.
_
(
'Subject'
),
xml_escape
(
entity
.
subject
)))
self
.
w
(
u
'</table></div><div class="emailcontent">'
)
for
part
in
entity
.
parts_in_order
():
content
,
mime
=
part
.
content
,
part
.
content_format
if
mime
==
'text/html'
:
content
=
soup2xhtml
(
content
,
self
.
req
.
encoding
)
content
=
soup2xhtml
(
content
,
self
.
_cw
.
encoding
)
elif
mime
!=
'text/xhtml'
:
content
=
xml_escape
(
content
)
if
mime
==
'text/plain'
:
...
...
@@ -81,7 +81,7 @@ class EmailHeadersView(baseviews.EntityView):
content_type
=
'text/plain'
def
cell_call
(
self
,
row
,
col
):
entity
=
self
.
entity
(
row
,
col
)
entity
=
self
.
cw_rset
.
get_
entity
(
row
,
col
)
self
.
w
(
entity
.
headers
)
...
...
@@ -93,18 +93,18 @@ class EmailOneLineView(baseviews.OneLineView):
title
=
_
(
'oneline'
)
def
cell_call
(
self
,
row
,
col
,
contexteid
=
None
):
entity
=
self
.
entity
(
row
,
col
)
entity
=
self
.
cw_rset
.
get_
entity
(
row
,
col
)
self
.
w
(
u
'<div class="email">'
)
self
.
w
(
u
'<i>%s %s</i> '
%
(
self
.
req
.
_
(
'email_date'
),
self
.
format_date
(
entity
.
date
,
time
=
True
)))
self
.
_cw
.
_
(
'email_date'
),
self
.
_cw
.
format_date
(
entity
.
date
,
time
=
True
)))
sender
=
entity
.
senderaddr
if
sender
is
None
or
contexteid
!=
sender
.
eid
:
self
.
w
(
u
'<b>%s</b> %s '
%
(
self
.
req
.
_
(
'email_from'
),
formated_sender
(
entity
)))
%
(
self
.
_cw
.
_
(
'email_from'
),
formated_sender
(
entity
)))
if
contexteid
not
in
(
r
.
eid
for
r
in
entity
.
recipients
):
recipients
=
', '
.
join
(
r
.
view
(
'oneline'
)
for
r
in
entity
.
recipients
)
self
.
w
(
u
'<b>%s</b> %s'
%
(
self
.
req
.
_
(
'email_to'
),
recipients
))
%
(
self
.
_cw
.
_
(
'email_to'
),
recipients
))
self
.
w
(
u
'<br/>
\n
<a href="%s">%s</a>'
%
(
xml_escape
(
entity
.
absolute_url
()),
xml_escape
(
entity
.
subject
)))
self
.
w
(
u
'</div>'
)
...
...
@@ -125,7 +125,7 @@ class EmailPartOutOfContextView(baseviews.OutOfContextView):
"""out of context an email part is redirecting to related email view"""
__select__
=
implements
(
'EmailPart'
)
def
cell_call
(
self
,
row
,
col
):
entity
=
self
.
entity
(
row
,
col
)
entity
=
self
.
cw_rset
.
get_
entity
(
row
,
col
)
entity
.
reverse_parts
[
0
].
view
(
'outofcontext'
,
w
=
self
.
w
)
...
...
@@ -141,7 +141,7 @@ class EmailThreadPrimaryView(primary.PrimaryView):
__select__
=
implements
(
'EmailThread'
)
def
cell_call
(
self
,
row
,
col
):
entity
=
self
.
complete_entity
(
row
,
col
)
entity
=
self
.
cw_rset
.
complete_entity
(
row
,
col
)
self
.
w
(
u
'<h1>%s</h1>'
%
xml_escape
(
entity
.
title
))
# get top level emails in this thread (ie message which are not a reply
# of a message in this thread)
...
...
@@ -155,7 +155,7 @@ class EmailThreadPrimaryView(primary.PrimaryView):
# NOT Y in_thread E, E eid %(x)s'
# to get message which are a reply of a message in another thread ?
# we may get duplicates in this case
rset
=
self
.
req
.
execute
(
'DISTINCT Any X,D ORDERBY D '
rset
=
self
.
_cw
.
execute
(
'DISTINCT Any X,D ORDERBY D '
'WHERE X date D, X in_thread E, '
'NOT X reply_to Y, E eid %(x)s'
,
{
'x'
:
entity
.
eid
},
'x'
)
...
...
Write
Preview
Supports
Markdown
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