|
1 """entity/relation schemas to store email in an cubicweb instance |
|
2 |
|
3 :organization: Logilab |
|
4 :copyright: 2006-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
6 """ |
|
7 __docformat__ = "restructuredtext en" |
|
8 from cubicweb import _ |
|
9 |
|
10 # pylint: disable-msg=E0611,F0401 |
|
11 from yams.buildobjs import (SubjectRelation, RelationType, EntityType, |
|
12 String, Datetime, Int, RelationDefinition) |
|
13 from yams.reader import context |
|
14 |
|
15 from cubicweb.schema import ERQLExpression |
|
16 |
|
17 |
|
18 class Email(EntityType): |
|
19 """electronic mail""" |
|
20 subject = String(fulltextindexed=True) |
|
21 date = Datetime(description=_('UTC time on which the mail was sent')) |
|
22 messageid = String(required=True, indexed=True) |
|
23 headers = String(description=_('raw headers')) |
|
24 |
|
25 sender = SubjectRelation('EmailAddress', cardinality='?*') |
|
26 # an email with only Bcc is acceptable, don't require any recipients |
|
27 recipients = SubjectRelation('EmailAddress') |
|
28 cc = SubjectRelation('EmailAddress') |
|
29 |
|
30 parts = SubjectRelation('EmailPart', cardinality='*1', composite='subject') |
|
31 attachment = SubjectRelation('File') |
|
32 |
|
33 reply_to = SubjectRelation('Email', cardinality='?*') |
|
34 cites = SubjectRelation('Email') |
|
35 in_thread = SubjectRelation('EmailThread', cardinality='?*') |
|
36 |
|
37 |
|
38 class EmailPart(EntityType): |
|
39 """an email attachment""" |
|
40 __permissions__ = { |
|
41 'read': ('managers', 'users', 'guests',), # XXX if E parts X, U has_read_permission E |
|
42 'add': ('managers', ERQLExpression('E parts X, U has_update_permission E'),), |
|
43 'delete': ('managers', ERQLExpression('E parts X, U has_update_permission E')), |
|
44 'update': ('managers', 'owners',), |
|
45 } |
|
46 |
|
47 content = String(fulltextindexed=True) |
|
48 content_format = String(required=True, maxsize=50) |
|
49 ordernum = Int(required=True) |
|
50 alternative = SubjectRelation('EmailPart', symmetric=True) |
|
51 |
|
52 |
|
53 class EmailThread(EntityType): |
|
54 """discussion thread""" |
|
55 title = String(required=True, indexed=True, fulltextindexed=True) |
|
56 see_also = SubjectRelation('EmailThread') |
|
57 forked_from = SubjectRelation('EmailThread', cardinality='?*') |
|
58 |
|
59 class parts(RelationType): |
|
60 """ """ |
|
61 fulltext_container = 'subject' |
|
62 |
|
63 class sender(RelationType): |
|
64 """ """ |
|
65 inlined = True |
|
66 |
|
67 class in_thread(RelationType): |
|
68 """ """ |
|
69 inlined = True |
|
70 |
|
71 class reply_to(RelationType): |
|
72 """ """ |
|
73 inlined = True |
|
74 |
|
75 class generated_by(RelationType): |
|
76 """mark an entity as generated from an email""" |
|
77 cardinality = '?*' |
|
78 subject = ('TrInfo',) |
|
79 object = 'Email' |
|
80 |
|
81 # if comment is installed |
|
82 if 'Comment' in context.defined: |
|
83 class comment_generated_by(RelationDefinition): |
|
84 subject = 'Comment' |
|
85 name = 'generated_by' |
|
86 object = 'Email' |