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
bb7aa8c654a4
Commit
ac7f358f
authored
Nov 16, 2009
by
Sylvain Thénault
Browse files
moved code as a generic text parser in the cw library, reimplement functionnality by using them
--HG-- branch : stable
parent
e4f29109f451
Changes
1
Hide whitespace changes
Inline
Side-by-side
hooks.py
View file @
bb7aa8c6
...
...
@@ -10,8 +10,6 @@
"""
__docformat__
=
"restructuredtext en"
import
re
from
logilab.mtconverter
import
TransformError
from
cubicweb
import
UnknownEid
,
typed_eid
...
...
@@ -67,45 +65,24 @@ class ExtractEmailInformation(PreCommitOperation):
fix_ownership
(
self
.
session
,
com
[
0
][
0
],
self
.
email
)
class
ExtractEmailChangeState
(
PreCommitOperation
):
class
AnalyzeEmailText
(
PreCommitOperation
):
"""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
):
...
...
@@ -123,4 +100,4 @@ class AddEmailHook(Hook):
if
info
:
ExtractEmailInformation
(
session
,
email
=
entity
,
info
=
info
)
break
ExtractEmailChangeState
(
session
,
email
=
entity
)
AnalyzeEmailText
(
session
,
email
=
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