def check_message(request, uid): em = Emailer(request.user) message = em.check_message(uid) # if we are POSTing, we are deleting if request.method == 'POST': success = em.delete_message(uid) if not success: return render_to_response('email/error.html', {'error_message': 'The message could not be deleted.', 'refresh': False }, context_instance=RequestContext(request)) return HttpResponseRedirect('/email/check/') # display error message, if applicable if type(message) == type((True, '')): return render_to_response('email/error.html', {'error_message': message[1], 'refresh': message[0] }, context_instance=RequestContext(request)) return render_to_response('email/check_message.html', {'email': message }, context_instance=RequestContext(request))
def send(request, user_ids): # check if we are sending to users if request.method == 'GET': usrs = user_ids.split(',') if len(user_ids) > 0: try: usrs = ['"%s" %s' %(u.get_full_name(), u.getEmail()) for u in gus_user.objects.filter(pk__in=usrs)] except: pass if request.method == 'POST': # If the form has been submitted... form = SendForm(request.POST) # A form bound to the POST data form.add_emails(request.user) if form.is_valid(): # All validation rules pass email = form.cleaned_data # add recipient if box checked for key in email.keys(): if key.startswith('to_email '): if len(email[key].strip()) == 0: continue for address in eval(email[key]): email['recipients'] += ' %s' % address em = Emailer(request.user) try: em.send_message(email['subject'], email['message'], email['recipients'].split() ) except SMTPException, e: email['message_send_failed'] = e email['success'] = False else: email['success'] = True return render_to_response('email/sent.html', {'email': email}, context_instance=RequestContext(request))
def check_sent(request, pagenum=1): # numberify pagenum - this will never fail due to the regex pagenum = int(pagenum) # fetch snippets em = Emailer(request.user) snippets = em.check_sent_email() # paginate the emails snippets_per_page = 10 paginator = Paginator(snippets, snippets_per_page) # default to last page if page number is invalid (too high) try: page = paginator.page(pagenum) except (EmptyPage, InvalidPage): page = paginator.page(paginator.num_pages) return render_to_response('email/check_sent.html', {'username':request.user.username, 'useremail':request.user.getEmail(), 'page': page, }, context_instance=RequestContext(request))