def add_message_from_mbox(self, mbox, user, project_name=None): def find_message_projects(m): return [p for p in Project.objects.all() if p.recognizes(m)] m = MboxMessage(mbox) msgid = m.get_message_id() if project_name: projects = [Project.object.get(name=project_name)] else: projects = find_message_projects(m) for p in projects: msg = Message(message_id=msgid, in_reply_to=m.get_in_reply_to() or "", date=m.get_date(), subject=m.get_subject(), stripped_subject=m.get_subject(strip_tags=True), version=m.get_version(), sender=m.get_from(), recipients=m.get_to() + m.get_cc(), prefixes=m.get_prefixes(), is_series_head=m.is_series_head(), is_patch=m.is_patch(), patch_num=m.get_num()[0]) msg.project = p if self.filter(message_id=msgid, project__name=p.name).first(): raise self.DuplicateMessageError(msgid) msg.save_mbox(mbox) msg.save() emit_event("MessageAdded", message=msg) self.update_series(msg) return projects
def create(self, project, **validated_data): mbox = validated_data.pop('mbox') m = MboxMessage(mbox) msg = Message(**validated_data) if 'in_reply_to' not in validated_data: msg.in_reply_to = m.get_in_reply_to() or "" msg.stripped_subject = m.get_subject(strip_tags=True) msg.version = m.get_version() msg.prefixes = m.get_prefixes() msg.is_series_head = m.is_series_head() msg.is_patch = m.is_patch() msg.patch_num = m.get_num()[0] msg.project = project msg.save_mbox(mbox) msg.save() emit_event("MessageAdded", message=msg) self.update_series(msg) return msg
def add_message_from_mbox(self, mbox, user, project_name=None): def find_message_projects(m): q = [] for name, addr in m.get_to() + m.get_cc(): q += Project.objects.filter(mailing_list__contains=addr) if not q: raise Exception("Cannot find project for message: %s" % m) return q m = MboxMessage(mbox) msgid = m.get_message_id() if project_name: projects = [Project.object.get(name=project_name)] else: projects = find_message_projects(m) for p in projects: msg = Message(message_id=msgid, in_reply_to=m.get_in_reply_to() or "", date=m.get_date(), subject=m.get_subject(), stripped_subject=m.get_subject(strip_tags=True), version=m.get_version(), sender=json.dumps(m.get_from()), receivers=json.dumps(m.get_to() + m.get_cc()), prefixes=json.dumps(m.get_prefixes()), is_series_head=m.is_series_head(), is_patch=m.is_patch(), patch_num=m.get_num()[0]) msg.project = p if self.filter(message_id=msgid, project__name=p.name).first(): raise self.DuplicateMessageError(msgid) msg.save_mbox(mbox) msg.save() emit_event("MessageAdded", message=msg) self.update_series(msg) return projects