Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubes
email
Commits
19fc50ba7cc1
Commit
49ada53e
authored
Dec 09, 2009
by
Sylvain Thénault
Browse files
merge
parents
bb86ab386838
bb7aa8c654a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
data/external_resources
View file @
19fc50ba
MAIL_ICON = DATADIR/mail.gif
NOMAIL_ICON = DATADIR/nomail.gif
hooks.py
View file @
19fc50ba
...
...
@@ -10,11 +10,9 @@
"""
__docformat__
=
"restructuredtext en"
import
re
from
logilab.mtconverter
import
TransformError
from
cubicweb
import
UnknownEid
from
cubicweb
import
UnknownEid
,
typed_eid
from
cubicweb.mail
import
parse_message_id
from
cubicweb.selectors
import
entity_implements
from
cubicweb.server
import
hook
...
...
@@ -38,7 +36,7 @@ class ExtractEmailInformation(hook.Operation):
email
=
self
.
email
# should create a Comment ?
info
=
self
.
info
origeid
=
int
(
info
[
'eid'
])
origeid
=
typed_eid
(
info
[
'eid'
])
try
:
origetype
=
self
.
session
.
describe
(
origeid
)[
0
]
except
UnknownEid
:
...
...
@@ -67,45 +65,24 @@ class ExtractEmailInformation(hook.Operation):
fix_ownership
(
self
.
session
,
com
[
0
][
0
],
self
.
email
)
class
ExtractEmailChangeState
(
hook
.
Operation
):
class
AnalyzeEmailText
(
hook
.
Operation
):
"""check if there are some change state instruction in the mail content"""
instr_rgx
=
re
.
compile
(
':(\w+):\s*#?(\d+)'
,
re
.
U
)
def
precommit_event
(
self
):
# should pass some transitions ?
text
=
self
.
email
.
subject
for
part
in
self
.
email
.
parts_in_order
(
prefered_mime_type
=
'text/plain'
):
try
:
text
+=
' '
+
part
.
actual_content
()
except
TransformError
:
continue
for
trname
,
eid
in
self
.
instr_rgx
.
findall
(
text
):
eid
=
int
(
eid
)
try
:
entity
=
self
.
session
.
entity
(
eid
)
except
UnknownEid
:
self
.
error
(
"can't get entity with eid %s"
,
eid
)
continue
if
not
hasattr
(
entity
,
'in_state'
):
self
.
error
(
'bad change state instruction for eid %s'
,
eid
)
continue
tr
=
entity
.
current_workflow
and
entity
.
current_workflow
.
transition_by_name
(
trname
)
if
tr
and
tr
.
may_be_fired
(
entity
.
eid
):
try
:
self
.
change_state
(
entity
,
tr
)
except
:
self
.
exception
(
'while changing state off %s from email %s'
,
entity
,
self
.
email
)
else
:
self
.
error
(
"can't pass transition %s on entity %s"
,
trname
,
entity
)
# XXX use user session if gpg signature validated
parser
=
self
.
session
.
vreg
[
'components'
].
select
(
'textanalyzer'
,
self
.
session
)
parser
.
parse
(
self
,
text
)
def
change_state
(
self
,
entity
,
transition
):
trinfo
=
entity
.
fire_transition
(
transition
)
self
.
session
.
execute
(
'SET X generated_by S WHERE X eid %(x)s, S eid %(s)s'
,
{
'x'
:
trinfo
.
eid
,
's'
:
self
.
email
.
eid
},
'x'
)
fix_ownership
(
self
.
session
,
trinfo
.
eid
,
self
.
email
)
def
fire_event
(
self
,
event
,
evargs
):
if
event
==
'state-changed'
:
evargs
[
'trinfo'
].
set_relations
(
generated_by
=
self
.
email
)
fix_ownership
(
self
.
session
,
evargs
[
'trinfo'
].
eid
,
self
.
email
)
class
AddEmailHook
(
hook
.
Hook
):
...
...
@@ -124,4 +101,4 @@ class AddEmailHook(hook.Hook):
if
info
:
ExtractEmailInformation
(
self
.
_cw
,
email
=
self
.
entity
,
info
=
info
)
break
ExtractEmailChangeState
(
self
.
_cw
,
email
=
self
.
entity
)
AnalyzeEmailText
(
self
.
_cw
,
email
=
self
.
entity
)
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