@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373an exception, the original message is bounced back to the sender with the
7474explanatory message given in the exception.
7575
76- $Id: mailgw.py,v 1.85 2002-09-10 03:01:18 richard Exp $
76+ $Id: mailgw.py,v 1.86 2002-09-10 12:44:42 richard Exp $
7777'''
7878
7979import string , re , os , mimetools , cStringIO , smtplib , socket , binascii , quopri
@@ -391,6 +391,63 @@ def handle_message(self, message):
391391Subject was: "%s"
392392''' % (nodeid , subject )
393393
394+ #
395+ # handle the users
396+ #
397+ # Don't create users if anonymous isn't allowed to register
398+ create = 1
399+ anonid = self .db .user .lookup ('anonymous' )
400+ if not self .db .security .hasPermission ('Email Registration' , anonid ):
401+ create = 0
402+
403+ # ok, now figure out who the author is - create a new user if the
404+ # "create" flag is true
405+ author = uidFromAddress (self .db , message .getaddrlist ('from' )[0 ],
406+ create = create )
407+
408+ # no author? means we're not author
409+ if not author :
410+ raise Unauthorized , '''
411+ You are not a registered user.
412+
413+ Unknown address: %s
414+ ''' % message .getaddrlist ('from' )[0 ][1 ]
415+
416+ # make sure the author has permission to use the email interface
417+ if not self .db .security .hasPermission ('Email Access' , author ):
418+ raise Unauthorized , 'You are not permitted to access this tracker.'
419+
420+ # make sure they're allowed to edit this class of information
421+ if not self .db .security .hasPermission ('Edit' , author , classname ):
422+ raise Unauthorized , 'You are not permitted to edit %s.' % classname
423+
424+ # the author may have been created - make sure the change is
425+ # committed before we reopen the database
426+ self .db .commit ()
427+
428+ # reopen the database as the author
429+ username = self .db .user .get (author , 'username' )
430+ self .db = self .instance .open (username )
431+
432+ # re-get the class with the new database connection
433+ cl = self .db .getclass (classname )
434+
435+ # now update the recipients list
436+ recipients = []
437+ tracker_email = self .instance .config .TRACKER_EMAIL .lower ()
438+ for recipient in message .getaddrlist ('to' ) + message .getaddrlist ('cc' ):
439+ r = recipient [1 ].strip ().lower ()
440+ if r == tracker_email or not r :
441+ continue
442+
443+ # look up the recipient - create if necessary (and we're
444+ # allowed to)
445+ recipient = uidFromAddress (self .db , recipient , create )
446+
447+ # if all's well, add the recipient to the list
448+ if recipient :
449+ recipients .append (recipient )
450+
394451 #
395452 # extract the args
396453 #
@@ -521,60 +578,6 @@ def handle_message(self, message):
521578Subject was: "%s"
522579''' % (errors , subject )
523580
524- #
525- # handle the users
526- #
527-
528- # Don't create users if anonymous isn't allowed to register
529- create = 1
530- anonid = self .db .user .lookup ('anonymous' )
531- if not self .db .security .hasPermission ('Email Registration' , anonid ):
532- create = 0
533-
534- # ok, now figure out who the author is - create a new user if the
535- # "create" flag is true
536- author = uidFromAddress (self .db , message .getaddrlist ('from' )[0 ],
537- create = create )
538-
539- # no author? means we're not author
540- if not author :
541- raise Unauthorized , '''
542- You are not a registered user.
543-
544- Unknown address: %s
545- ''' % message .getaddrlist ('from' )[0 ][1 ]
546-
547- # make sure the author has permission to use the email interface
548- if not self .db .security .hasPermission ('Email Access' , author ):
549- raise Unauthorized , 'You are not permitted to access this tracker.'
550-
551- # the author may have been created - make sure the change is
552- # committed before we reopen the database
553- self .db .commit ()
554-
555- # reopen the database as the author
556- username = self .db .user .get (author , 'username' )
557- self .db = self .instance .open (username )
558-
559- # re-get the class with the new database connection
560- cl = self .db .getclass (classname )
561-
562- # now update the recipients list
563- recipients = []
564- tracker_email = self .instance .config .TRACKER_EMAIL .lower ()
565- for recipient in message .getaddrlist ('to' ) + message .getaddrlist ('cc' ):
566- r = recipient [1 ].strip ().lower ()
567- if r == tracker_email or not r :
568- continue
569-
570- # look up the recipient - create if necessary (and we're
571- # allowed to)
572- recipient = uidFromAddress (self .db , recipient , create )
573-
574- # if all's well, add the recipient to the list
575- if recipient :
576- recipients .append (recipient )
577-
578581 #
579582 # handle message-id and in-reply-to
580583 #
0 commit comments