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 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 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 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")