mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-06-20 01:27:44 +02:00
UP: When multiple emails are used on the "To" field, subscribe them as well.
This commit is contained in:
parent
5933d2a59b
commit
c5101a2873
@ -12,6 +12,7 @@ scripts/get_email.py - Designed to be run from cron, this script checks the
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import email
|
import email
|
||||||
|
from email.utils import getaddresses
|
||||||
import imaplib
|
import imaplib
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import poplib
|
import poplib
|
||||||
@ -172,11 +173,17 @@ def decode_mail_headers(string):
|
|||||||
|
|
||||||
def create_ticket_cc(ticket, cc_list):
|
def create_ticket_cc(ticket, cc_list):
|
||||||
|
|
||||||
|
if not cc_list:
|
||||||
|
return []
|
||||||
|
|
||||||
# Local import to deal with non-defined / circular reference problem
|
# Local import to deal with non-defined / circular reference problem
|
||||||
from helpdesk.views.staff import User, subscribe_to_ticket_updates
|
from helpdesk.views.staff import User, subscribe_to_ticket_updates
|
||||||
|
|
||||||
new_ticket_ccs = []
|
new_ticket_ccs = []
|
||||||
for cced_email in cc_list:
|
for cced_name, cced_email in cc_list:
|
||||||
|
|
||||||
|
if cced_email == ticket.queue.email_address:
|
||||||
|
continue
|
||||||
|
|
||||||
user = None
|
user = None
|
||||||
cced_email = cced_email.strip()
|
cced_email = cced_email.strip()
|
||||||
@ -202,9 +209,11 @@ def create_object_from_email_message(message, ticket_id, payload, files, quiet):
|
|||||||
queue = payload['queue']
|
queue = payload['queue']
|
||||||
sender_email = payload['sender_email']
|
sender_email = payload['sender_email']
|
||||||
|
|
||||||
|
to_list = getaddresses(message.get_all('To', []))
|
||||||
|
cc_list = getaddresses(message.get_all('Cc', []))
|
||||||
|
|
||||||
message_id = message.get('Message-Id')
|
message_id = message.get('Message-Id')
|
||||||
in_reply_to = message.get('In-Reply-To')
|
in_reply_to = message.get('In-Reply-To')
|
||||||
cc_list = message.get('Cc')
|
|
||||||
|
|
||||||
if in_reply_to is not None:
|
if in_reply_to is not None:
|
||||||
try:
|
try:
|
||||||
@ -279,8 +288,8 @@ def create_object_from_email_message(message, ticket_id, payload, files, quiet):
|
|||||||
context = safe_template_context(ticket)
|
context = safe_template_context(ticket)
|
||||||
|
|
||||||
new_ticket_ccs = []
|
new_ticket_ccs = []
|
||||||
if cc_list is not None:
|
new_ticket_ccs.append(create_ticket_cc(ticket, to_list))
|
||||||
new_ticket_ccs = create_ticket_cc(ticket, cc_list.split(','))
|
new_ticket_ccs.append(create_ticket_cc(ticket, cc_list))
|
||||||
|
|
||||||
notification_template = None
|
notification_template = None
|
||||||
notifications_to_be_sent = [sender_email,]
|
notifications_to_be_sent = [sender_email,]
|
||||||
|
@ -122,6 +122,7 @@ class EmailInteractionsTestCase(TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.queue_public = Queue.objects.create(title='Mail Queue 1',
|
self.queue_public = Queue.objects.create(title='Mail Queue 1',
|
||||||
slug='mq1',
|
slug='mq1',
|
||||||
|
email_address='queue-1@example.com',
|
||||||
allow_public_submission=True,
|
allow_public_submission=True,
|
||||||
new_ticket_cc='new.public.with.notifications@example.com',
|
new_ticket_cc='new.public.with.notifications@example.com',
|
||||||
updated_ticket_cc='update.public.with.notifications@example.com',
|
updated_ticket_cc='update.public.with.notifications@example.com',
|
||||||
@ -130,6 +131,7 @@ class EmailInteractionsTestCase(TestCase):
|
|||||||
|
|
||||||
self.queue_public_with_notifications_disabled = Queue.objects.create(title='Mail Queue 2',
|
self.queue_public_with_notifications_disabled = Queue.objects.create(title='Mail Queue 2',
|
||||||
slug='mq2',
|
slug='mq2',
|
||||||
|
email_address='queue-2@example.com',
|
||||||
allow_public_submission=True,
|
allow_public_submission=True,
|
||||||
new_ticket_cc='new.public.without.notifications@example.com',
|
new_ticket_cc='new.public.without.notifications@example.com',
|
||||||
updated_ticket_cc='update.public.without.notifications@example.com',
|
updated_ticket_cc='update.public.without.notifications@example.com',
|
||||||
@ -247,6 +249,56 @@ class EmailInteractionsTestCase(TestCase):
|
|||||||
self.assertIn(submitter_email,mail.outbox[0].to)
|
self.assertIn(submitter_email,mail.outbox[0].to)
|
||||||
|
|
||||||
|
|
||||||
|
for cc_email in cc_list:
|
||||||
|
|
||||||
|
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
||||||
|
self.assertIn(cc_email, mail.outbox[0].to)
|
||||||
|
|
||||||
|
# Ensure that <TicketCC> exists
|
||||||
|
ticket_cc = TicketCC.objects.get(ticket=ticket, email=cc_email)
|
||||||
|
self.assertTrue(ticket_cc.ticket, ticket)
|
||||||
|
self.assertTrue(ticket_cc.email, cc_email)
|
||||||
|
|
||||||
|
def test_create_ticket_from_email_to_multiple_emails(self):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Ensure that an instance of <TicketCC> is created for every valid element of the
|
||||||
|
"rfc_2822_cc" field when creating a <Ticket> instance.
|
||||||
|
"""
|
||||||
|
|
||||||
|
msg = email.message.Message()
|
||||||
|
|
||||||
|
message_id = uuid.uuid4().hex
|
||||||
|
submitter_email = 'foo@bar.py'
|
||||||
|
to_list = [self.queue_public.email_address]
|
||||||
|
cc_list = ['bravo@example.net', 'charlie@foobar.com']
|
||||||
|
|
||||||
|
msg.__setitem__('Message-ID', message_id)
|
||||||
|
msg.__setitem__('Subject', self.ticket_data['title'])
|
||||||
|
msg.__setitem__('From', submitter_email)
|
||||||
|
msg.__setitem__('To', ','.join(to_list + cc_list))
|
||||||
|
msg.__setitem__('Content-Type', 'text/plain;')
|
||||||
|
msg.set_payload(self.ticket_data['description'])
|
||||||
|
|
||||||
|
email_count = len(mail.outbox)
|
||||||
|
|
||||||
|
object_from_message(str(msg), self.queue_public, quiet=True)
|
||||||
|
|
||||||
|
followup = FollowUp.objects.get(message_id=message_id)
|
||||||
|
ticket = Ticket.objects.get(id=followup.ticket.id)
|
||||||
|
self.assertEqual(ticket.ticket_for_url, "mq1-%s" % ticket.id)
|
||||||
|
|
||||||
|
# As we have created an Ticket from an email, we notify the sender
|
||||||
|
# and contacts on the cc_list (+1 as it's treated as a list),
|
||||||
|
# the new and update queues (+2)
|
||||||
|
self.assertEqual(email_count + 1 + 2, len(mail.outbox))
|
||||||
|
|
||||||
|
# Ensure that the submitter is notified
|
||||||
|
self.assertIn(submitter_email,mail.outbox[0].to)
|
||||||
|
|
||||||
|
# Ensure that the queue's email was not subscribed to the event notifications.
|
||||||
|
self.assertRaises(TicketCC.DoesNotExist, TicketCC.objects.get, ticket=ticket, email=to_list[0])
|
||||||
|
|
||||||
for cc_email in cc_list:
|
for cc_email in cc_list:
|
||||||
|
|
||||||
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
# Ensure that contacts on cc_list will be notified on the same email (index 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user