Commit 8dc5d992 authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

delete-trailing-whitespace

parent bfb0d17a344e
......@@ -11,7 +11,7 @@ def parse_body(body, quote='>'):
"""return a `ParsedMessage` instance where actual content is separated from
cited content
"""
res = []
res = []
level = 0
current = []
seenlevels = set()
......@@ -57,7 +57,7 @@ class ParsedMessage(object):
@property
def cited_content(self):
return '\n'.join(self.cites)
# import sys
# from mailbox import UnixMailbox
# from maboa.umessage import message_from_file
......@@ -98,7 +98,7 @@ class ParsedMessage(object):
# for message in mailbox:
# body = self._get_body(message)
# yield parse_body(body)
# def process_mailbox(self, filename):
# """
# """
......@@ -119,7 +119,7 @@ class ParsedMessage(object):
# cites.setdefault((index,index2), [])
# cites[(index, index2)].append( (cite, para) )
# return msgs, cites
# if __name__ == '__main__':
# from pprint import pprint
# msgs, cites = CitesDetector().process_mailbox(sys.argv[1])
......
......@@ -34,7 +34,7 @@ def fix_ownership(session, eid, email):
class ExtractEmailInformation(PreCommitOperation):
"""generate a comment on the original entity if supported"""
def precommit_event(self):
email = self.email
# should create a Comment ?
......@@ -57,7 +57,7 @@ class ExtractEmailInformation(PreCommitOperation):
except:
self.exception('while generating comment on %s from email %s',
origeid, email)
def insert_comment(self, eid, emailpart):
com = self.session.unsafe_execute(
'INSERT Comment C: C content %(content)s, '
......@@ -70,9 +70,9 @@ class ExtractEmailInformation(PreCommitOperation):
class ExtractEmailChangeState(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
......@@ -101,7 +101,7 @@ class ExtractEmailChangeState(PreCommitOperation):
else:
self.error("can't pass transition %s on entity %s",
trname, entity)
def change_state(self, entity, transition):
entity.change_state(transition.destination_state[0].eid)
trinfo = entity.latest_trinfo()
......@@ -109,13 +109,13 @@ class ExtractEmailChangeState(PreCommitOperation):
{'x': trinfo.eid, 's': self.email.eid}, 'x')
fix_ownership(self.session, trinfo.eid, self.email)
class AddEmailHook(Hook):
"""an email has been added, check if associated content should be created
"""
events = ('after_add_entity',)
accepts = ('Email',)
def call(self, session, entity):
if 'comments' in session.repo.schema:
for msgid in entity.references():
......
......@@ -17,7 +17,7 @@ def cleanup_subject(string):
def combinaison(list):
"""given a list return an iterator on possible combinaisons between all the
elements in the list but without identity:
>>> list(combinaison([1,2,3]))
[(1, 2), (2, 3), (1, 3)]
>>> list(combinaison([1,2,3,4]))
......@@ -28,10 +28,10 @@ def combinaison(list):
first = list.pop()
for i in list:
yield (first, i)
class MBOXImporter:
"""import content of a Unix mailbox into cubicweb as Email (and related) objects"""
def __init__(self, cursor, schema,
verbose=False, interactive=False):
self.cursor = cursor
......@@ -48,17 +48,17 @@ class MBOXImporter:
def autocommit_mode(self, cnx):
self.autocommit = True
self.cnx = cnx
def _notify_created(self, etype, eid):
if self._verbose:
print 'create', etype, eid
self.created.setdefault(etype, []).append(eid)
def _notify_skipped(self, messageid):
if self._verbose:
print 'skipping', messageid
self.skipped.append(messageid)
def import_mbox_stream(self, stream):
from mailbox import UnixMailbox
from logilab.common.umessage import message_from_file
......@@ -80,7 +80,7 @@ class MBOXImporter:
break
else:
raise
def import_message(self, message):
# check this email hasn't been imported
messageid = message.get('message-id')
......@@ -138,7 +138,7 @@ class MBOXImporter:
if mlrset:
self.execute('SET X sent_on Y WHERE X eid %(x)s, Y eid %(y)s',
{'x': eid, 'y': mlrset[0][0]})
def import_message_parts(self, message, emaileid):
# XXX only parts and attachments are used not content, alternative...
if message.is_multipart():
......@@ -155,7 +155,7 @@ class MBOXImporter:
self._context = None
else:
self._import_message_part(message, emaileid)
def _import_message_part(self, part, emaileid):
"""finally import a non multipart message (ie non MIME message or a
not compound part of a MIME message
......@@ -180,7 +180,7 @@ class MBOXImporter:
parteid = self.execute('INSERT File F: F name %(name)s,'
'F data %(data)s, F data_format %(mtype)s,'
'F data_encoding %(encoding)s',
{'name': name, 'data': Binary(data),
{'name': name, 'data': Binary(data),
'mtype': contenttype,
'encoding': encoding})[0][0]
self._notify_created('file', parteid)
......@@ -191,7 +191,7 @@ class MBOXImporter:
parteid = self.execute('INSERT EmailPart X: '
'X content %(data)s, X content_format %(mtype)s,'
'X ordernum %(i)s',
{'data': data,
{'data': data,
'mtype': contenttype,
'i': self._part_index})[0][0]
self._notify_created('emailpart', parteid)
......@@ -227,7 +227,7 @@ class MBOXImporter:
{'y': replyeid})
if rset:
return rset[0][0]
subject = cleanup_subject(subject)
subject = cleanup_subject(subject)
rset = self.execute('EmailThread X WHERE X title %(title)s',
{'title': subject})
if rset:
......@@ -236,4 +236,4 @@ class MBOXImporter:
{'title': subject})
self._notify_created('emailthread', rset[0][0])
return rset[0][0]
......@@ -13,15 +13,15 @@ class Email(EntityType):
date = Datetime(description=_('UTC time on which the mail was sent'))
messageid = String(required=True, indexed=True)
headers = String(description=_('raw headers'))
sender = SubjectRelation('EmailAddress', cardinality='?*')
# an email with only Bcc is acceptable, don't require any recipients
recipients = SubjectRelation('EmailAddress')
cc = SubjectRelation('EmailAddress')
parts = SubjectRelation('EmailPart', cardinality='*1', composite='subject')
attachment = SubjectRelation('File') # XXX Image should be there until it inherits from File
reply_to = SubjectRelation('Email', cardinality='?*')
cites = SubjectRelation('Email')
in_thread = SubjectRelation('EmailThread', cardinality='?*')
......@@ -35,33 +35,33 @@ class EmailPart(MetaEntityType):
'delete': ('managers', ERQLExpression('E parts X, U has_update_permission E')),
'update': ('managers', 'owners',),
}
content = String(fulltextindexed=True)
content_format = String(required=True, meta=True, maxsize=50)
ordernum = Int(required=True)
alternative = SubjectRelation('EmailPart', symetric=True)
class EmailThread(EntityType):
"""discussion thread"""
title = String(required=True, indexed=True, fulltextindexed=True)
see_also = SubjectRelation('EmailThread')
forked_from = SubjectRelation('EmailThread', cardinality='?*')
class parts(RelationType):
""""""
""" """
fulltext_container = 'subject'
class sender(RelationType):
""""""
""" """
inlined = True
class in_thread(RelationType):
""""""
""" """
inlined = True
class reply_to(RelationType):
""""""
""" """
inlined = True
class generated_by(RelationType):
......@@ -76,11 +76,11 @@ if 'Comment' in defined_types:
subject = 'Comment'
name = 'generated_by'
object = 'Email'
#class Role(Entity):
# SubjectRelation('name', 'String')
#class PersonThreadRole(Entity):
......@@ -45,6 +45,6 @@ def install(**kwargs):
url=web,
data_files=data_files,
**kwargs)
if __name__ == '__main__' :
install()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment