def START(message, list_name=None, host=None, bad_list=None): if bad_list: if '-' in bad_list: # probably put a '.' in it, try to find a similar list similar_lists = mailinglist.similar_named_lists(bad_list.replace('-','.')) else: similar_lists = mailinglist.similar_named_lists(bad_list) help = view.respond(locals(), "mail/bad_list_name.msg", From="noreply@%(host)s", To=message['from'], Subject="That's not a valid list name.") relay.deliver(help) return START elif list_name in INVALID_LISTS or message['from'].endswith(host): logging.debug("LOOP MESSAGE to %r from %r.", message['to'], message['from']) return START elif mailinglist.find_list(list_name): action = "subscribe to" CONFIRM.send(relay, list_name, message, 'mail/confirmation.msg', locals()) return CONFIRMING_SUBSCRIBE else: similar_lists = mailinglist.similar_named_lists(list_name) CONFIRM.send(relay, list_name, message, 'mail/create_confirmation.msg', locals()) return CONFIRMING_SUBSCRIBE
def START(message, list_name=None, host=None, bad_list=None): if bad_list: if '-' in bad_list: # probably put a '.' in it, try to find a similar list similar_lists = mailinglist.similar_named_lists( bad_list.replace('-', '.')) else: similar_lists = mailinglist.similar_named_lists(bad_list) help = view.respond(locals(), "mail/bad_list_name.msg", From="noreply@%(host)s", To=message['from'], Subject="That's not a valid list name.") relay.deliver(help) return START elif list_name in INVALID_LISTS or message['from'].endswith(host): logging.debug("LOOP MESSAGE to %r from %r.", message['to'], message['from']) return START elif mailinglist.find_list(list_name): action = "subscribe to" CONFIRM.send(relay, list_name, message, 'mail/confirmation.msg', locals()) return CONFIRMING_SUBSCRIBE else: similar_lists = mailinglist.similar_named_lists(list_name) CONFIRM.send(relay, list_name, message, 'mail/create_confirmation.msg', locals()) return CONFIRMING_SUBSCRIBE
def POSTING(message, list_name=None, id_number=None, host=None): """ Takes a message and posts it to the rest of the group. If there are multiple email addresses in the To or CC field, those emails will be added to the list. We also ensure that they don't receive a duplicate of the email they were just sent. """ #an existing user is adding themselves to another group. if id_number: START(message, list_name=list_name, id_number=id_number, host=None) else: list_addr = "%s@%s" % (list_name, host) if mailinglist.is_subscribed(message['from'], list_name) and mailinglist.is_active(list_name): mlist = mailinglist.find_list(list_name) #send a request for confirmation to anyone cc'd on this list so they can #join the group if they want. allrecpts = mailinglist.all_recpts(message) for address in [to for to in allrecpts if not to.endswith(host)]: CONFIRM.send_if_not_subscriber(relay, mlist, 'confirm', address, 'postosaurus/join-confirmation.msg', host) delivery = mailinglist.craft_response(message, list_name, list_addr) mailinglist.post_message(relay, message, delivery, list_name, host, message['from']) q = queue.Queue("run/work") q.push(message) return POSTING
def START(message, user_id=None, host=None): if user_id: market_anon = addressing.mapping(message['from'], 'marketroid', host) reply = filter.cleanse_incoming(message, user_id, host, market_anon) relay.deliver(reply) return DEMARKETING else: CONFIRM.send(relay, "start", message, "mail/start_confirm.msg", locals()) return CONFIRMING
def POSTING(message, list_name=None, action=None, host=None): if action == 'unsubscribe': action = "unsubscribe from" CONFIRM.send(relay, list_name, message, 'mail/confirmation.msg', locals()) return CONFIRMING_UNSUBSCRIBE else: mailinglist.post_message(relay, message, list_name, host) # archive makes sure it gets cleaned up before archival final_msg = mailinglist.craft_response(message, list_name, list_name + '@' + host) archive.enqueue(list_name, final_msg) return POSTING
def CONFIRMING_SUBSCRIBE(message, list_name=None, id_number=None, host=None): original = CONFIRM.verify(list_name, message['from'], id_number) if original: mailinglist.add_subscriber(message['from'], list_name) msg = view.respond(locals(), "mail/subscribed.msg", From="noreply@%(host)s", To=message['from'], Subject="Welcome to %(list_name)s list.") relay.deliver(msg) CONFIRM.cancel(list_name, message['from'], id_number) return POSTING else: logging.warning("Invalid confirm from %s", message['from']) return CONFIRMING_SUBSCRIBE
def CONFIRMING_UNBOUNCE(message, id_number=None, host=None): original = CONFIRM.verify("unbounce", message["from"], id_number) if original: relay.deliver(bounce.you_are_now_unbounced(message)) name, address = parseaddr(message["from"]) Router.STATE_STORE.set_all(address, "POSTING") mailinglist.enable_all_subscriptions(message["from"]) return UNBOUNCED
def CONFIRMING_UNBOUNCE(message, id_number=None, host=None): original = CONFIRM.verify('unbounce', message['from'], id_number) if original: relay.deliver(bounce.you_are_now_unbounced(message)) name, address = parseaddr(message['from']) Router.STATE_STORE.set_all(address, 'POSTING') mailinglist.enable_all_subscriptions(message['from']) return UNBOUNCED
def CONFIRMING_UNSUBSCRIBE(message, list_name=None, id_number=None, host=None): original = CONFIRM.verify(list_name, message['from'], id_number) if original: mailinglist.remove_subscriber(message['from'], list_name) msg = view.respond(locals(), 'mail/unsubscribed.msg', From="noreply@%(host)s", To=message['from'], Subject="You are now unsubscribed from %(list_name)s.") relay.deliver(msg) CONFIRM.cancel(list_name, message['from'], id_number) return START else: logging.warning("Invalid unsubscribe confirm from %s", message['from']) return CONFIRMING_UNSUBSCRIBE
def POSTING(message, group_name=None, action=None, topic=None, host=None): #group_name = group_name.lower() if group_name else None #action = action.lower() if action else None host = host.lower() if host else None if topic == 'unsubscribe': topic = "unsubscribe from" CONFIRM.send(relay, group_name, message, 'mail/confirmation.msg', locals()) return CONFIRMING_UNSUBSCRIBE else: mailinglist.post_message(relay, message, group_name, host) # archive makes sure it gets cleaned up before archival final_msg = mailinglist.craft_response(message, group_name, group_name + '@' + host) archive.enqueue(group_name, final_msg) # TODO: Save message in DB? # TODO: if topic: Link message to topic, attach message attachments to topic return POSTING
def test_subscribe_user(sender=sender, client=client, mlist=None): if not mlist: mlist = MailingList.objects.filter(email=list_addr)[0] subs = len(mlist.subscription_set.all()) msg = CONFIRM.send_if_not_subscriber(relay, mlist, "confirm", sender, "postosaurus/join-confirmation.msg", host) client.say(msg["from"], "subscribe me") newsubs = len(mlist.subscription_set.all()) assert newsubs == subs + 1, "Should be %s subscriptions but there are %s" % (str(subs + 1), str(newsubs)) assert_in_state("app.handlers.admin", msg["from"], msg["to"], "POSTING")
def CONFIRMING_UNSUBSCRIBE(message, list_name=None, id_number=None, host=None): original = CONFIRM.verify(list_name, message['from'], id_number) if original: mailinglist.remove_subscriber(message['from'], list_name) msg = view.respond( locals(), 'mail/unsubscribed.msg', From="noreply@%(host)s", To=message['from'], Subject="You are now unsubscribed from %(list_name)s.") relay.deliver(msg) CONFIRM.cancel(list_name, message['from'], id_number) return START else: logging.warning("Invalid unsubscribe confirm from %s", message['from']) return CONFIRMING_UNSUBSCRIBE
def user_main(request): try: profile = request.user.get_profile() subscriptions = profile.subscription_set.all() mlists = [sub.mailing_list for sub in subscriptions] except ValueError: raise Http404() form = MailingListForm() mlist = None if request.method == "POST": form = MailingListForm(request.POST) # Let them know they need to pay up to create another list. if not profile.can_create_list(): return render_to_response('postosaurus/usermain.html', { 'profile' : profile, 'subscriptions' : subscriptions, 'mlists' : mlists, 'groupstab' : True, 'form': form, 'payup' : True, }, context_instance = RequestContext(request)) #Check if the mailing list is valid. if form.is_valid(): email = profile.email list_name = form.cleaned_data['groupname'] mlist = mailinglist.create_list(list_name, profile) CONFIRM.send_if_not_subscriber(relay, mlist, 'confirm', email, 'postosaurus/join-confirmation.msg') return render_to_response('postosaurus/usermain.html', { 'profile' : profile, 'subscriptions' : subscriptions, 'mlist' : mlist, 'mlists' : mlists, 'groupstab' : True, 'form' : form, 'payup' : False, }, context_instance = RequestContext(request))
def CONFIRMING_SUBSCRIBE(message, group_name=None, id_number=None, host=None): #group_name = group_name.lower() if group_name else None host = host.lower() if host else None original = CONFIRM.verify(group_name, message.route_from, id_number) if original: mailinglist.add_subscriber(message.route_from, group_name) msg = view.respond(locals(), "mail/subscribed.msg", From="noreply@%(host)s", To=message['from'], Subject="Welcome to %(group_name)s group.") relay.deliver(msg) CONFIRM.cancel(group_name, message.route_from, id_number) return POSTING else: logging.warning("Invalid confirm from %s", message.route_from) return CONFIRMING_SUBSCRIBE
def test_existing_user_new_list(): test_subscribe_user() mlist = MailingList(name="newlist", email="*****@*****.**") mlist.save() subs = len(mlist.subscription_set.all()) assert subs == 0 msg = CONFIRM.send_if_not_subscriber(relay, mlist, "confirm", sender, "postosaurus/join-confirmation.msg", host) client.say(msg["from"], "subscribe me") newsubs = len(mlist.subscription_set.all()) assert newsubs == subs + 1, "Should be %s subscriptions but there are %s" % (str(subs + 1), str(newsubs)) assert_in_state("app.handlers.admin", msg["from"], msg["to"], "POSTING")
def START(message, list_name=None, id_number=None, host=None): """ The start state looks for confirmation emails and move users with valid confirmation emails into a posting state. We also create the user's postosaurus account (if needed) and subscription here. This prevents users from being added to a list if they don't want to be. """ mlist = mailinglist.find_list(list_name) if mlist: if CONFIRM.verify(mlist, 'confirm', message['from'], id_number): # Let them know they've been added. name, address = parseaddr(message['from']) CONFIRM.notify(relay, mlist, 'confirm', address) user = mailinglist.find_user(address) if not user: user = mailinglist.create_user(address) mailinglist.add_if_not_subscriber(address, list_name) return POSTING return START
def START(message, group_name=None, topic=None, host=None, bad_list=None): #group_name = group_name.lower() if group_name else None #bad_list = bad_list.lower() if bad_list else None host = host.lower() if host else None logging.debug("Group name: "+group_name) if bad_list: help = view.respond(locals(), "mail/bad_list_name.msg", From="noreply@%(host)s", To=message['from'], Subject="That's not a valid list name.") relay.deliver(help) return START elif group_name in INVALID_LISTS or message.route_from.endswith(host): logging.debug("LOOP MESSAGE to %r from %r.", message['to'], message.route_from) return START group = mailinglist.find_group(group_name) if group: action = "subscribe to" activity = group.find_topic(topic) if topic else None # TODO: put activity and topic in message template CONFIRM.send(relay, group_name, message, 'mail/confirmation.msg', locals()) return CONFIRMING_SUBSCRIBE else: similar_groups = mailinglist.similar_named_groups(group_name) CONFIRM.send(relay, group_name, message, 'mail/create_confirmation.msg', locals()) return CONFIRMING_SUBSCRIBE
def CONFIRMING(message, id_number=None, host=None): original = CONFIRM.verify('start', message['from'], id_number) if original: user_anon = addressing.mapping(message['from'], 'user', host) welcome = view.respond(locals(), "mail/welcome.msg", From=user_anon, To=message['from'], Subject="Welcome to MyInboxIsNotA.TV") relay.deliver(welcome) return PROTECTING else: logging.warning("Invalid confirm from %s", message['from']) return CONFIRMING
def CONFIRMING(message, id_number=None, host=None): original = CONFIRM.verify('comment', message['from'], id_number) if original: # headers are already attached from START comment.defer_to_queue(original) msg = view.respond(locals(), "mail/comment_submitted.msg", From="noreply@%(host)s", To=original['from'], Subject="Your comment has been posted.") relay.deliver(msg) return COMMENTING else: logging.debug("Invalid confirm from %s", message['from']) return CONFIRMING
def CONFIRMING(message, id_number=None, host=None): original = CONFIRM.verify('post', message['from'], id_number) if original: name, address = parseaddr(original['from']) post_name = original['x-post-name'] post_id = post.post(post_name, address, host, original) msg = view.respond(locals(), "mail/welcome.msg", From="noreply@%(host)s", To=message['from'], Subject="Welcome, your blog is ready.") relay.deliver(msg) return POSTING else: logging.warning("Invalid confirm from %s", message['from']) return CONFIRMING
def BOUNCING(message, host=None): CONFIRM.send(relay, 'unbounce', message, 'mail/unbounce_confirm.msg', locals()) return CONFIRMING_UNBOUNCE
def BOUNCING(message, host=None): CONFIRM.send(relay, "unbounce", message, "mail/unbounce_confirm.msg", locals()) return CONFIRMING_UNBOUNCE
def START(message, user_id=None, post_name=None, host=None, domain=None): comment.attach_headers(message, user_id, post_name, domain) CONFIRM.send(relay, "comment", message, "mail/comment_confirm.msg", locals()) return CONFIRMING
def START(message, post_name=None, host=None): message['X-Post-Name'] = post_name CONFIRM.send(relay, "post", message, "mail/confirm.msg", locals()) return CONFIRMING