def remind(request, bug): if request.method == 'POST': reminderForm = ReminderForm(request.POST, user=request.user) if reminderForm.is_valid(): reminder_text = reminderForm.cleaned_data['text'] reminder_recipients = reminderForm.cleaned_data['recipients'] """ save note """ bugnote = Bugnote(bug=bug, reporter=request.user, text='Reminder to %s: %s' % (', '.join(map(str, reminder_recipients)), reminder_text), scope=reminderForm.cleaned_data['scope']) bugnote.save() """ send reminder """ send_alerts(bug, reminder_recipients, reminder_text) request.user.message_set.create(message=_('Reminder(s) sent')) return HttpResponseRedirect(bug.get_absolute_url()) else: reminderForm = ReminderForm(user=request.user) return direct_to_template(request, 'picket/reminder.html', {'bug': bug, 'reminder_form': reminderForm,})
def process_message(self, peer, mailfrom, rcpttos, data): """ peer is a tuple containing (ipaddr, port) of the client that made the socket connection to our smtp port. mailfrom is the raw address the client claims the message is coming from. rcpttos is a list of raw addresses the client wishes to deliver the message to. data is a string containing the entire full text of the message, headers (if supplied) and all. It has been `de-transparencied' according to RFC 821, Section 4.5.2. In other words, a line containing a `.' followed by other text has had the leading dot removed. This function should return None, for a normal `250 Ok' response; otherwise it returns the desired response string in RFC 821 format. Picket mail processing algorithm: 1. Find category via rcpttos or drop message 2. Try to find user for mailfrom or create new one 2. Try to find bug to post reply or assume new bug In case of reply (even bug moved to other category) create bugnote with text from message body In case of new bug create new bug with summary from mail subject and text from message body 3. Create bugfiles from attachments """ """ HACK aka crutch Reopen database connection in current thread. We close it, and django open it again in current thread. """ from django.db import connection connection.close() """ find all categories mail sent to """ categories = Category.objects.filter(mail_addr__in=rcpttos) """ do anything if there is any categories only """ if categories.count() > 0: """ find or create user for mailfrom """ try: user = User.objects.get(email=mailfrom) except User.DoesNotExist: username = mailfrom.split('@', 1)[0] + \ str(User.objects.all().order_by('-id')[0].id + 1) user = User.objects.create_user(username, mailfrom) user.groups.add(Group.objects.get(name=SMTP_USERS_GROUP)) """ connect history handler """ bugHistoryHandler = BugHistoryHandler(user) """ make message object """ message = email.message_from_string(data) """ try to find bug """ subject_parsed = subject_regex.search(message['subject']) \ if 'subject' in message else '' if subject_parsed: bug_id = subject_parsed.group('bug_id') if bug_id: try: bug = Bug.objects.get(id=bug_id) except: """ if bug not found will create new one """ pass else: """ we have reply here """ try: Bugnote.from_message(bug, user, message).save() except Exception, e: result = '451 %s' % e else: result = OK