Skip to content

Commit a00dfc0

Browse files
authored
chore: remove unused submit by email functionality (#7249)
1 parent 891c0e9 commit a00dfc0

File tree

11 files changed

+43
-1158
lines changed

11 files changed

+43
-1158
lines changed

ietf/mailtrigger/utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,5 @@ def starts_with(prefix):
149149
return sorted(rule_list)
150150

151151

152-
def get_base_submission_message_address():
153-
return Recipient.objects.get(slug="submission_manualpost_handling").gather()[0]
154-
155-
156152
def get_base_ipr_request_address():
157153
return Recipient.objects.get(slug="ipr_requests").gather()[0]

ietf/submit/mail.py

Lines changed: 2 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
11
# Copyright The IETF Trust 2013-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

4-
5-
import re
6-
import email
7-
import base64
84
import os
9-
import pyzmail
105

116
from django.conf import settings
127
from django.urls import reverse as urlreverse
13-
from django.core.exceptions import ValidationError
148
from django.contrib.sites.models import Site
159
from django.template.loader import render_to_string
16-
from django.utils.encoding import force_str
1710

1811
import debug # pyflakes:ignore
1912

20-
from ietf.utils.log import log
2113
from ietf.utils.mail import send_mail, send_mail_message
2214
from ietf.doc.models import Document
23-
from ietf.ipr.mail import utc_from_string
2415
from ietf.person.models import Person
25-
from ietf.message.models import Message, MessageAttachment
16+
from ietf.message.models import Message
2617
from ietf.utils.accesstoken import generate_access_token
27-
from ietf.mailtrigger.utils import gather_address_lists, get_base_submission_message_address
28-
from ietf.submit.models import SubmissionEmailEvent, Submission
18+
from ietf.mailtrigger.utils import gather_address_lists
2919
from ietf.submit.checkers import DraftIdnitsChecker
30-
from ietf.utils.timezone import date_today
3120

3221

3322
def send_submission_confirmation(request, submission, chair_notice=False):
@@ -196,181 +185,3 @@ def announce_to_authors(request, submission):
196185
'group': group},
197186
cc=cc)
198187

199-
200-
def get_reply_to():
201-
"""Returns a new reply-to address for use with an outgoing message. This is an
202-
address with "plus addressing" using a random string. Guaranteed to be unique"""
203-
local,domain = get_base_submission_message_address().split('@')
204-
while True:
205-
rand = force_str(base64.urlsafe_b64encode(os.urandom(12)))
206-
address = "{}+{}@{}".format(local,rand,domain)
207-
q = Message.objects.filter(reply_to=address)
208-
if not q:
209-
return address
210-
211-
212-
def process_response_email(msg):
213-
"""Saves an incoming message. msg=string. Message "To" field is expected to
214-
be in the format ietf-submit+[identifier]@ietf.org. Expect to find a message with
215-
a matching value in the reply_to field, associated to a submission.
216-
Create a Message object for the incoming message and associate it to
217-
the original message via new SubmissionEvent"""
218-
message = email.message_from_string(force_str(msg))
219-
to = message.get('To')
220-
221-
# exit if this isn't a response we're interested in (with plus addressing)
222-
local,domain = get_base_submission_message_address().split('@')
223-
if not re.match(r'^{}\+[a-zA-Z0-9_\-]{}@{}'.format(local,'{16}',domain),to):
224-
return None
225-
226-
try:
227-
to_message = Message.objects.get(reply_to=to)
228-
except Message.DoesNotExist:
229-
log('Error finding matching message ({})'.format(to))
230-
return None
231-
232-
try:
233-
submission = to_message.manualevents.first().submission
234-
except:
235-
log('Error processing message ({})'.format(to))
236-
return None
237-
238-
if not submission:
239-
log('Error processing message - no submission ({})'.format(to))
240-
return None
241-
242-
parts = pyzmail.parse.get_mail_parts(message)
243-
body=''
244-
for part in parts:
245-
if part.is_body == 'text/plain' and part.disposition == None:
246-
payload, used_charset = pyzmail.decode_text(part.get_payload(), part.charset, None)
247-
body = body + payload + '\n'
248-
249-
by = Person.objects.get(name="(System)")
250-
msg = submit_message_from_message(message, body, by)
251-
252-
desc = "Email: received message - manual post - {}-{}".format(
253-
submission.name,
254-
submission.rev)
255-
256-
submission_email_event = SubmissionEmailEvent.objects.create(
257-
submission = submission,
258-
desc = desc,
259-
msgtype = 'msgin',
260-
by = by,
261-
message = msg,
262-
in_reply_to = to_message
263-
)
264-
265-
save_submission_email_attachments(submission_email_event, parts)
266-
267-
log("Received submission email from %s" % msg.frm)
268-
return msg
269-
270-
271-
def add_submission_email(request, remote_ip, name, rev, submission_pk, message, by, msgtype):
272-
"""Add email to submission history"""
273-
274-
#in_reply_to = form.cleaned_data['in_reply_to']
275-
# create Message
276-
parts = pyzmail.parse.get_mail_parts(message)
277-
body=''
278-
for part in parts:
279-
if part.is_body == 'text/plain' and part.disposition == None:
280-
payload, used_charset = pyzmail.decode_text(part.get_payload(), part.charset, None)
281-
body = body + payload + '\n'
282-
283-
msg = submit_message_from_message(message, body, by)
284-
285-
if (submission_pk != None):
286-
# Must exist - we're adding a message to an existing submission
287-
submission = Submission.objects.get(pk=submission_pk)
288-
else:
289-
# Must not exist
290-
submissions = Submission.objects.filter(name=name,rev=rev).exclude(state_id='cancel')
291-
if submissions.count() > 0:
292-
raise ValidationError("Submission {} already exists".format(name))
293-
294-
# create Submission using the name
295-
try:
296-
submission = Submission.objects.create(
297-
state_id="waiting-for-draft",
298-
remote_ip=remote_ip,
299-
name=name,
300-
rev=rev,
301-
title=name,
302-
note="",
303-
submission_date=date_today(),
304-
replaces="",
305-
)
306-
from ietf.submit.utils import create_submission_event, docevent_from_submission
307-
desc = "Submission created for rev {} in response to email".format(rev)
308-
create_submission_event(request,
309-
submission,
310-
desc)
311-
docevent_from_submission(submission, desc)
312-
except Exception as e:
313-
log("Exception: %s\n" % e)
314-
raise
315-
316-
if msgtype == 'msgin':
317-
rs = "Received"
318-
else:
319-
rs = "Sent"
320-
321-
desc = "{} message - manual post - {}-{}".format(rs, name, rev)
322-
submission_email_event = SubmissionEmailEvent.objects.create(
323-
desc = desc,
324-
submission = submission,
325-
msgtype = msgtype,
326-
by = by,
327-
message = msg)
328-
#in_reply_to = in_reply_to
329-
330-
save_submission_email_attachments(submission_email_event, parts)
331-
return submission, submission_email_event
332-
333-
334-
def submit_message_from_message(message,body,by=None):
335-
"""Returns a ietf.message.models.Message. msg=email.Message
336-
A copy of mail.message_from_message with different body handling
337-
"""
338-
if not by:
339-
by = Person.objects.get(name="(System)")
340-
msg = Message.objects.create(
341-
by = by,
342-
subject = message.get('subject',''),
343-
frm = message.get('from',''),
344-
to = message.get('to',''),
345-
cc = message.get('cc',''),
346-
bcc = message.get('bcc',''),
347-
reply_to = message.get('reply_to',''),
348-
body = body,
349-
time = utc_from_string(message.get('date', '')),
350-
content_type = message.get('content_type', 'text/plain'),
351-
)
352-
return msg
353-
354-
def save_submission_email_attachments(submission_email_event, parts):
355-
for part in parts:
356-
if part.disposition != 'attachment':
357-
continue
358-
359-
if part.type == 'text/plain':
360-
payload, used_charset = pyzmail.decode_text(part.get_payload(),
361-
part.charset,
362-
None)
363-
encoding = ""
364-
else:
365-
# Need a better approach - for the moment we'll just handle these
366-
# and encode as base64
367-
payload = base64.b64encode(part.get_payload())
368-
encoding = "base64"
369-
370-
#name = submission_email_event.submission.name
371-
372-
MessageAttachment.objects.create(message = submission_email_event.message,
373-
content_type = part.type,
374-
encoding = encoding,
375-
filename=part.filename,
376-
body=payload)

ietf/submit/management/commands/manualpost_email.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)