schema.py 2.82 KB
Newer Older
Nicolas Chauvat's avatar
Nicolas Chauvat committed
1
2
3
"""entity/relation schemas to store email in an cubicweb instance

:organization: Logilab
Nicolas Chauvat's avatar
Nicolas Chauvat committed
4
:copyright: 2006-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
Nicolas Chauvat's avatar
Nicolas Chauvat committed
5
6
7
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__ = "restructuredtext en"
8
9
10
11
12

try:
    from cubicweb import _
except ImportError:
    _ = unicode
Nicolas Chauvat's avatar
Nicolas Chauvat committed
13

Aurelien Campeas's avatar
Aurelien Campeas committed
14
# pylint: disable-msg=E0611,F0401
15
from yams.buildobjs import (SubjectRelation, RelationType, EntityType,
Aurelien Campeas's avatar
Aurelien Campeas committed
16
                            String, Datetime, Int, RelationDefinition)
Sylvain Thénault's avatar
cleanup    
Sylvain Thénault committed
17
18
from yams.reader import context

Aurelien Campeas's avatar
Aurelien Campeas committed
19
from cubicweb.schema import ERQLExpression
Nicolas Chauvat's avatar
Nicolas Chauvat committed
20

Sylvain Thénault's avatar
Sylvain Thénault committed
21

Nicolas Chauvat's avatar
Nicolas Chauvat committed
22
23
24
25
class Email(EntityType):
    """electronic mail"""
    subject   = String(fulltextindexed=True)
    date      = Datetime(description=_('UTC time on which the mail was sent'))
26
    messageid = String(required=True, indexed=True, unique=True)
Nicolas Chauvat's avatar
Nicolas Chauvat committed
27
    headers   = String(description=_('raw headers'))
Nicolas Chauvat's avatar
Nicolas Chauvat committed
28

29
    sender     = SubjectRelation('EmailAddress', cardinality='?*')
Nicolas Chauvat's avatar
Nicolas Chauvat committed
30
31
32
    # an email with only Bcc is acceptable, don't require any recipients
    recipients = SubjectRelation('EmailAddress')
    cc         = SubjectRelation('EmailAddress')
Nicolas Chauvat's avatar
Nicolas Chauvat committed
33

Nicolas Chauvat's avatar
Nicolas Chauvat committed
34
    parts       = SubjectRelation('EmailPart', cardinality='*1', composite='subject')
35
    attachment  = SubjectRelation('File')
Nicolas Chauvat's avatar
Nicolas Chauvat committed
36

Nicolas Chauvat's avatar
Nicolas Chauvat committed
37
38
39
40
41
    reply_to    = SubjectRelation('Email', cardinality='?*')
    cites       = SubjectRelation('Email')
    in_thread   = SubjectRelation('EmailThread', cardinality='?*')


42
class EmailPart(EntityType):
Nicolas Chauvat's avatar
Nicolas Chauvat committed
43
    """an email attachment"""
Sylvain Thénault's avatar
Sylvain Thénault committed
44
    __permissions__ = {
Nicolas Chauvat's avatar
Nicolas Chauvat committed
45
46
47
48
49
        'read':   ('managers', 'users', 'guests',), # XXX if E parts X, U has_read_permission E
        'add':    ('managers', ERQLExpression('E parts X, U has_update_permission E'),),
        'delete': ('managers', ERQLExpression('E parts X, U has_update_permission E')),
        'update': ('managers', 'owners',),
        }
Nicolas Chauvat's avatar
Nicolas Chauvat committed
50

Nicolas Chauvat's avatar
Nicolas Chauvat committed
51
    content  = String(fulltextindexed=True)
52
    content_format = String(required=True, maxsize=50)
Nicolas Chauvat's avatar
Nicolas Chauvat committed
53
    ordernum = Int(required=True)
Sylvain Thénault's avatar
Sylvain Thénault committed
54
    alternative = SubjectRelation('EmailPart', symmetric=True)
Nicolas Chauvat's avatar
Nicolas Chauvat committed
55

Nicolas Chauvat's avatar
Nicolas Chauvat committed
56
57
58
59
60
61

class EmailThread(EntityType):
    """discussion thread"""
    title = String(required=True, indexed=True, fulltextindexed=True)
    see_also = SubjectRelation('EmailThread')
    forked_from = SubjectRelation('EmailThread', cardinality='?*')
Nicolas Chauvat's avatar
Nicolas Chauvat committed
62

Nicolas Chauvat's avatar
Nicolas Chauvat committed
63
class parts(RelationType):
Nicolas Chauvat's avatar
Nicolas Chauvat committed
64
    """ """
Nicolas Chauvat's avatar
Nicolas Chauvat committed
65
    fulltext_container = 'subject'
Nicolas Chauvat's avatar
Nicolas Chauvat committed
66

Nicolas Chauvat's avatar
Nicolas Chauvat committed
67
class sender(RelationType):
Nicolas Chauvat's avatar
Nicolas Chauvat committed
68
    """ """
Nicolas Chauvat's avatar
Nicolas Chauvat committed
69
    inlined = True
Nicolas Chauvat's avatar
Nicolas Chauvat committed
70

Nicolas Chauvat's avatar
Nicolas Chauvat committed
71
class in_thread(RelationType):
Nicolas Chauvat's avatar
Nicolas Chauvat committed
72
    """ """
Nicolas Chauvat's avatar
Nicolas Chauvat committed
73
    inlined = True
Nicolas Chauvat's avatar
Nicolas Chauvat committed
74

Nicolas Chauvat's avatar
Nicolas Chauvat committed
75
class reply_to(RelationType):
Nicolas Chauvat's avatar
Nicolas Chauvat committed
76
    """ """
Nicolas Chauvat's avatar
Nicolas Chauvat committed
77
78
79
80
81
82
83
84
85
    inlined = True

class generated_by(RelationType):
    """mark an entity as generated from an email"""
    cardinality = '?*'
    subject = ('TrInfo',)
    object = 'Email'

# if comment is installed
Sylvain Thénault's avatar
cleanup    
Sylvain Thénault committed
86
if 'Comment' in context.defined:
Nicolas Chauvat's avatar
Nicolas Chauvat committed
87
88
89
90
    class comment_generated_by(RelationDefinition):
        subject = 'Comment'
        name = 'generated_by'
        object = 'Email'
Nicolas Chauvat's avatar
Nicolas Chauvat committed
91

Nicolas Chauvat's avatar
Nicolas Chauvat committed
92