def handle(message, pseudo, stranger_address): """ Stranger emailing a pseudonym New strangers will be added as Contact. Strangers sending from invalid domain will be flagged. Args: message: InboundEmailMessage pseudo: Pseudonym of user stranger_email: str in 'x@x' format """ contact = model.get( model.Contact, pseudonym=pseudo, email=stranger_address.email ) # Create entry if new new_prefix = '' if not contact: contact = model.Contact( pseudonym=pseudo, email=stranger_address.email, name=stranger_address.name, mask=util.generate_random_string(), ) contact.put() new_prefix = 'New ' logging.info("MAIL: %sContact: %s -> %s" % ( new_prefix, stranger_address.email, pseudo.email )) # Test for spam and add link generation should_drop = prepare_message( message, pseudo, stranger_address, ) if should_drop: return message.to = pseudo.member.user.email() # This is important because it lets the user know WHO EMAILED THEM message.sender = "'%s <%s>' <%s+%s@%s>" % ( # ie "'Bob Frizzel <*****@*****.**>' <*****@*****.**>" contact.name, contact.email, pseudo.mask, contact.mask, dontspamme.config.mail_domain ) logging.debug("Body ======== \n%s" % message.html.decode()) message.send()
def get_valid_member(self): current_user = users.get_current_user() valid_user = model.get( model.Member, user=current_user ) member = valid_user or self.create_admin_if_needed(current_user) if not member: user_regex = re.compile(re.escape(current_user.email()), re.IGNORECASE) user_len = len(current_user.email()) for m in model.Member.all(): # TODO: Look into how this might open a security hole (if it smells like a pig and tastes like a pig, it might be bacon) # Update user references to actual user reference if user_regex.match(m.user.email()) and len(m.user.email()) == user_len: m.user = current_user m.put() member = m break if not member: self.redirect(self.EXIT) return return member
def get_valid_member(self): current_user = users.get_current_user() valid_user = model.get(model.Member, user=current_user) member = valid_user or self.create_admin_if_needed(current_user) if not member: user_regex = re.compile(re.escape(current_user.email()), re.IGNORECASE) user_len = len(current_user.email()) for m in model.Member.all(): # TODO: Look into how this might open a security hole (if it smells like a pig and tastes like a pig, it might be bacon) # Update user references to actual user reference if user_regex.match(m.user.email()) and len( m.user.email()) == user_len: m.user = current_user m.put() member = m break if not member: self.redirect(self.EXIT) return return member
def handle(message, pseudo, to_address): """ Send reply to contact. Sanitize message, verify contact contact mask, send email to contact. Args: message: InboundEmailMessage pseudo: Pseudonym of user to_address: recipient """ contact = model.get(model.Contact, pseudonym=pseudo, mask=to_address.contact) # Invalid contact mask if not contact: # TODO: Should we warn user that they have sent invalid contact mask? logging.info("MAIL: Invalid Reply contact: %s+%s -> ?" % ( pseudo.mask, to_address.contact, )) return logging.info("MAIL: Reply: '%s' -> '%s'" % (pseudo.email, contact.email)) # Send message sanitize_message(message, pseudo, to_address, contact) message.sender = pseudo.email message.to = contact.email message.send()
def handle(message, pseudo, to_address): """ Send reply to contact. Sanitize message, verify contact contact mask, send email to contact. Args: message: InboundEmailMessage pseudo: Pseudonym of user to_address: recipient """ contact = model.get( model.Contact, pseudonym=pseudo, mask=to_address.contact ) # Invalid contact mask if not contact: # TODO: Should we warn user that they have sent invalid contact mask? logging.info("MAIL: Invalid Reply contact: %s+%s -> ?" % ( pseudo.mask, to_address.contact, )) return logging.info("MAIL: Reply: '%s' -> '%s'" % (pseudo.email, contact.email)) # Send message sanitize_message(message, pseudo, to_address, contact) message.sender = pseudo.email message.to = contact.email message.send()
def post(self, member, variables): if 'mask' not in variables or 'domain' not in variables: return self.HOME if ' ' in variables['domain']: return self.HOME # Pseudonym in db? pseudo = model.get( model.Pseudonym, mask=variables['mask'].lower(), member=member ) if not pseudo: return self.HOME domain = variables['domain'].lower() if domain not in pseudo.domains: pseudo.domains.append(domain) pseudo.put() logging.info("WEB: %s added '%s' to mask '%s'" % ( member.user.email(), domain, pseudo.mask ))
def create_admin_if_needed(self, user): if users.is_current_user_admin(): member = model.get(model.Member, user=user) if not member: member = model.Member(user=user) member.put() return member
def create_admin_if_needed(self, user): if users.is_current_user_admin(): member = model.get( model.Member, user=user ) if not member: member = model.Member(user=user) member.put() return member
def handle(message, pseudo, stranger_address): """ Stranger emailing a pseudonym New strangers will be added as Contact. Strangers sending from invalid domain will be flagged. Args: message: InboundEmailMessage pseudo: Pseudonym of user stranger_email: str in 'x@x' format """ contact = model.get(model.Contact, pseudonym=pseudo, email=stranger_address.email) # Create entry if new new_prefix = '' if not contact: contact = model.Contact( pseudonym=pseudo, email=stranger_address.email, name=stranger_address.name, mask=util.generate_random_string(), ) contact.put() new_prefix = 'New ' logging.info("MAIL: %sContact: %s -> %s" % (new_prefix, stranger_address.email, pseudo.email)) # Test for spam and add link generation should_drop = prepare_message( message, pseudo, stranger_address, ) if should_drop: return message.to = pseudo.member.user.email() # This is important because it lets the user know WHO EMAILED THEM message.sender = "'%s <%s>' <%s+%s@%s>" % ( # ie "'Bob Frizzel <*****@*****.**>' <*****@*****.**>" contact.name, contact.email, pseudo.mask, contact.mask, dontspamme.config.mail_domain) logging.debug("Body ======== \n%s" % message.html.decode()) message.send()
def receive(self, message): """ Called when message an email message is received. Args: message: InboundEmailMessage """ # To a pseudonym we know? to_address = util.EmailAddress(message.to) pseudo = model.get(model.Pseudonym, mask=to_address.user.lower()) # Not stranger or reply? if not pseudo: logging.info("MAIL: No such pseudonym") return sender_address = util.EmailAddress(message.sender) # No contact in to address? if not to_address.contact: # Not user emailing their own pseudonym # TODO: Maybe we should change the response? if pseudo.member.user.email().lower() == sender_address.email.lower(): logging.info("MAIL: User emailed themself") return from_stranger.handle( message, pseudo, util.EmailAddress(message.sender) ) return # A reply to a contact, from the user's REAL email? if pseudo.member.user.email() == sender_address.email: from_user.handle(message, pseudo, to_address) return # Not from correct user... logging.info("MAIL: Invalid sender '%s' for reply to '%s+%s'" % ( message.sender, pseudo.mask, to_address.contact ))
def post(self, member, variables): if 'email' not in variables: return '/admin' user = User(variables['email']) # TODO: Add error checking for non-existent users # User already in db? member = model.get( model.Member, user=user ) if member: return '/admin' # Perform add model.Member(user=user).put() logging.info("WEB: Added member '%s'" % variables['email']) return '/admin'
def receive(self, message): """ Called when message an email message is received. Args: message: InboundEmailMessage """ # To a pseudonym we know? to_address = util.EmailAddress(message.to) pseudo = model.get(model.Pseudonym, mask=to_address.user.lower()) # Not stranger or reply? if not pseudo: logging.info("MAIL: No such pseudonym") return sender_address = util.EmailAddress(message.sender) # No contact in to address? if not to_address.contact: # Not user emailing their own pseudonym # TODO: Maybe we should change the response? if pseudo.member.user.email().lower( ) == sender_address.email.lower(): logging.info("MAIL: User emailed themself") return from_stranger.handle(message, pseudo, util.EmailAddress(message.sender)) return # A reply to a contact, from the user's REAL email? if pseudo.member.user.email() == sender_address.email: from_user.handle(message, pseudo, to_address) return # Not from correct user... logging.info("MAIL: Invalid sender '%s' for reply to '%s+%s'" % (message.sender, pseudo.mask, to_address.contact))
def post(self, member, variables): if 'mask' not in variables: return self.HOME # Pseudonym in db? pseudo = model.get( model.Pseudonym, mask=variables['mask'].lower(), member=member ) if not pseudo: return self.HOME # Perform action pseudo.should_drop = not pseudo.should_drop pseudo.put() logging.info("WEB: %s set drop to '%r' for mask '%s'" % ( member.user.email(), pseudo.should_drop, pseudo.mask ))
def post(self, member, variables): if 'email' not in variables: return '/admin' # TODO: Add error checking for non-existent users # User in db? member = model.get( model.Member, user=User(variables['email']) ) if not member: return '/admin' # Perform deletion for pseudo in member.pseudonyms: for contact in pseudo.contacts: contact.delete() pseudo.delete() member.delete() logging.info("WEB: Deleted member '%s'" % variables['email']) return '/admin'
def post(self, member, variables): if 'mask' not in variables: return self.HOME # Pseudonym in db? pseudo = model.get( model.Pseudonym, mask=variables['mask'].lower(), member=member ) if not pseudo: return self.HOME # Perform action for contact in pseudo.contacts: contact.delete() logging.info("WEB: %s deleted mask '%s'" % ( member.user.email(), pseudo.mask )) pseudo.delete()
def post(self, member, variables): if 'mask' not in variables or 'domain' not in variables: return self.HOME # Pseudonym in db? pseudo = model.get( model.Pseudonym, mask=variables['mask'].lower(), member=member ) if not pseudo: return self.HOME domain = variables['domain'].lower() if domain in pseudo.domains and len(pseudo.domains) > 1: pseudo.domains.remove(domain) pseudo.put() logging.info("WEB: %s removed '%s' from mask '%s'" % ( member.user.email(), domain, pseudo.mask ))