Mercurial > p > roundup > code
comparison roundup/mailgw.py @ 699:676d4cfde9a5
Nosy list improvements.
. added option to automatically add the authors and recipients of messages
to the nosy lists with the options ADD_AUTHOR_TO_NOSY (default 'new') and
ADD_RECIPIENTS_TO_NOSY (default 'new'). These settings emulate the current
behaviour. Setting them to 'yes' will add the author/recipients to the nosy
on messages that create issues and followup messages.
. added missing documentation for a few of the config option values
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 02 May 2002 07:56:34 +0000 |
| parents | 34dbcdfb2fe1 |
| children | 7ba403bffed5 |
comparison
equal
deleted
inserted
replaced
| 698:a26afb64a947 | 699:676d4cfde9a5 |
|---|---|
| 71 set() method to add the message to the item's spool; in the second case we | 71 set() method to add the message to the item's spool; in the second case we |
| 72 are calling the create() method to create a new node). If an auditor raises | 72 are calling the create() method to create a new node). If an auditor raises |
| 73 an exception, the original message is bounced back to the sender with the | 73 an exception, the original message is bounced back to the sender with the |
| 74 explanatory message given in the exception. | 74 explanatory message given in the exception. |
| 75 | 75 |
| 76 $Id: mailgw.py,v 1.67 2002-04-23 15:46:49 rochecompaan Exp $ | 76 $Id: mailgw.py,v 1.68 2002-05-02 07:56:34 richard Exp $ |
| 77 ''' | 77 ''' |
| 78 | 78 |
| 79 | 79 |
| 80 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri | 80 import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri |
| 81 import time, random | 81 import time, random |
| 129 self.db = db | 129 self.db = db |
| 130 | 130 |
| 131 def main(self, fp): | 131 def main(self, fp): |
| 132 ''' fp - the file from which to read the Message. | 132 ''' fp - the file from which to read the Message. |
| 133 ''' | 133 ''' |
| 134 self.handle_Message(Message(fp)) | 134 return self.handle_Message(Message(fp)) |
| 135 | 135 |
| 136 def handle_Message(self, message): | 136 def handle_Message(self, message): |
| 137 '''Handle an RFC822 Message | 137 '''Handle an RFC822 Message |
| 138 | 138 |
| 139 Handle the Message object by calling handle_message() and then cope | 139 Handle the Message object by calling handle_message() and then cope |
| 491 tracker_email = self.instance.ISSUE_TRACKER_EMAIL.lower() | 491 tracker_email = self.instance.ISSUE_TRACKER_EMAIL.lower() |
| 492 for recipient in message.getaddrlist('to') + message.getaddrlist('cc'): | 492 for recipient in message.getaddrlist('to') + message.getaddrlist('cc'): |
| 493 r = recipient[1].strip().lower() | 493 r = recipient[1].strip().lower() |
| 494 if r == tracker_email or not r: | 494 if r == tracker_email or not r: |
| 495 continue | 495 continue |
| 496 recipients.append(self.db.uidFromAddress(recipient)) | 496 |
| 497 # look up the recipient - create if necessary (and we're | |
| 498 # allowed to) | |
| 499 recipient = self.db.uidFromAddress(recipient, create) | |
| 500 | |
| 501 # if all's well, add the recipient to the list | |
| 502 if recipient: | |
| 503 recipients.append(recipient) | |
| 497 | 504 |
| 498 # | 505 # |
| 499 # handle message-id and in-reply-to | 506 # handle message-id and in-reply-to |
| 500 # | 507 # |
| 501 messageid = message.getheader('message-id') | 508 messageid = message.getheader('message-id') |
| 636 if (not props.has_key('status') and | 643 if (not props.has_key('status') and |
| 637 current_status == unread_id or | 644 current_status == unread_id or |
| 638 current_status == resolved_id): | 645 current_status == resolved_id): |
| 639 props['status'] = chatting_id | 646 props['status'] = chatting_id |
| 640 | 647 |
| 641 # add nosy in arguments to issue's nosy list | 648 # update the nosy list |
| 642 if not props.has_key('nosy'): props['nosy'] = [] | 649 current = {} |
| 643 n = {} | |
| 644 for nid in cl.get(nodeid, 'nosy'): | 650 for nid in cl.get(nodeid, 'nosy'): |
| 645 n[nid] = 1 | 651 current[nid] = 1 |
| 646 for value in props['nosy']: | 652 self.updateNosy(props, author, recipients, current) |
| 647 if self.db.hasnode('user', value): | 653 |
| 648 nid = value | 654 # create the message |
| 649 else: | |
| 650 continue | |
| 651 if n.has_key(nid): continue | |
| 652 n[nid] = 1 | |
| 653 props['nosy'] = n.keys() | |
| 654 # add assignedto to the nosy list | |
| 655 if props.has_key('assignedto'): | |
| 656 assignedto = props['assignedto'] | |
| 657 if assignedto not in props['nosy']: | |
| 658 props['nosy'].append(assignedto) | |
| 659 | |
| 660 message_id = self.db.msg.create(author=author, | 655 message_id = self.db.msg.create(author=author, |
| 661 recipients=recipients, date=date.Date('.'), summary=summary, | 656 recipients=recipients, date=date.Date('.'), summary=summary, |
| 662 content=content, files=files, messageid=messageid, | 657 content=content, files=files, messageid=messageid, |
| 663 inreplyto=inreplyto) | 658 inreplyto=inreplyto) |
| 664 try: | 659 try: |
| 709 | 704 |
| 710 # pre-load the messages list | 705 # pre-load the messages list |
| 711 props['messages'] = [message_id] | 706 props['messages'] = [message_id] |
| 712 | 707 |
| 713 # set up (clean) the nosy list | 708 # set up (clean) the nosy list |
| 714 nosy = props.get('nosy', []) | 709 self.updateNosy(props, author, recipients) |
| 715 n = {} | |
| 716 for value in nosy: | |
| 717 nid = value | |
| 718 if n.has_key(nid): continue | |
| 719 n[nid] = 1 | |
| 720 props['nosy'] = n.keys() | |
| 721 # add on the recipients of the message | |
| 722 for recipient in recipients: | |
| 723 if not n.has_key(recipient): | |
| 724 props['nosy'].append(recipient) | |
| 725 n[recipient] = 1 | |
| 726 | |
| 727 # add the author to the nosy list | |
| 728 if not n.has_key(author): | |
| 729 props['nosy'].append(author) | |
| 730 n[author] = 1 | |
| 731 | |
| 732 # add assignedto to the nosy list | |
| 733 if properties.has_key('assignedto') and props.has_key('assignedto'): | |
| 734 assignedto = props['assignedto'] | |
| 735 if not n.has_key(assignedto): | |
| 736 props['nosy'].append(assignedto) | |
| 737 n[assignedto] = 1 | |
| 738 | 710 |
| 739 # and attempt to create the new node | 711 # and attempt to create the new node |
| 740 try: | 712 try: |
| 741 nodeid = cl.create(**props) | 713 nodeid = cl.create(**props) |
| 742 except (TypeError, IndexError, ValueError), message: | 714 except (TypeError, IndexError, ValueError), message: |
| 745 %s | 717 %s |
| 746 '''%message | 718 '''%message |
| 747 | 719 |
| 748 # commit the new node(s) to the DB | 720 # commit the new node(s) to the DB |
| 749 self.db.commit() | 721 self.db.commit() |
| 722 | |
| 723 return nodeid | |
| 724 | |
| 725 def updateNosy(self, props, author, recipients, current=None): | |
| 726 '''Determine what the nosy list should be given: | |
| 727 | |
| 728 props: properties specified on the subject line of the message | |
| 729 author: the sender of the message | |
| 730 recipients: the recipients (to, cc) of the message | |
| 731 current: if the issue already exists, this is the current nosy | |
| 732 list, as a dictionary. | |
| 733 ''' | |
| 734 if current is None: | |
| 735 current = {} | |
| 736 ok = ('new', 'yes') | |
| 737 else: | |
| 738 ok = ('yes',) | |
| 739 | |
| 740 # add nosy in arguments to issue's nosy list | |
| 741 nosy = props.get('nosy', []) | |
| 742 for value in nosy: | |
| 743 if not self.db.hasnode('user', value): | |
| 744 continue | |
| 745 if not current.has_key(value): | |
| 746 current[value] = 1 | |
| 747 | |
| 748 # add the author to the nosy list | |
| 749 if getattr(self.instance, 'ADD_AUTHOR_TO_NOSY', 'new') in ok: | |
| 750 if not current.has_key(author): | |
| 751 current[author] = 1 | |
| 752 | |
| 753 # add on the recipients of the message | |
| 754 if getattr(self.instance, 'ADD_RECIPIENTS_TO_NOSY', 'new') in ok: | |
| 755 for recipient in recipients: | |
| 756 if not current.has_key(recipient): | |
| 757 current[recipient] = 1 | |
| 758 | |
| 759 # add assignedto to the nosy list | |
| 760 if props.has_key('assignedto'): | |
| 761 assignedto = props['assignedto'] | |
| 762 if not current.has_key(assignedto): | |
| 763 current[assignedto] = 1 | |
| 764 | |
| 765 props['nosy'] = current.keys() | |
| 750 | 766 |
| 751 def parseContent(content, keep_citations, keep_body, | 767 def parseContent(content, keep_citations, keep_body, |
| 752 blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'), | 768 blank_line=re.compile(r'[\r\n]+\s*[\r\n]+'), |
| 753 eol=re.compile(r'[\r\n]+'), | 769 eol=re.compile(r'[\r\n]+'), |
| 754 signature=re.compile(r'^[>|\s]*[-_]+\s*$')): | 770 signature=re.compile(r'^[>|\s]*[-_]+\s*$')): |
| 810 content = '\n\n'.join(l) | 826 content = '\n\n'.join(l) |
| 811 return summary, content | 827 return summary, content |
| 812 | 828 |
| 813 # | 829 # |
| 814 # $Log: not supported by cvs2svn $ | 830 # $Log: not supported by cvs2svn $ |
| 831 # Revision 1.67 2002/04/23 15:46:49 rochecompaan | |
| 832 # . stripping of the email message body can now be controlled through | |
| 833 # the config variables EMAIL_KEEP_QUOTED_TEST and | |
| 834 # EMAIL_LEAVE_BODY_UNCHANGED. | |
| 835 # | |
| 815 # Revision 1.66 2002/03/14 23:59:24 richard | 836 # Revision 1.66 2002/03/14 23:59:24 richard |
| 816 # . #517734 ] web header customisation is obscure | 837 # . #517734 ] web header customisation is obscure |
| 817 # | 838 # |
| 818 # Revision 1.65 2002/02/15 00:13:38 richard | 839 # Revision 1.65 2002/02/15 00:13:38 richard |
| 819 # . #503204 ] mailgw needs a default class | 840 # . #503204 ] mailgw needs a default class |
