summaryrefslogtreecommitdiffstats
path: root/hyperkitty/lib/__init__.py
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2013-07-05 13:25:47 +0200
committerAurélien Bompard <aurelien@bompard.org>2013-07-05 13:25:47 +0200
commitecca23e67b63ef6c9577652a7ea820645a3d9b55 (patch)
tree9666b059700531f6be00ff362798b585852ea4bc /hyperkitty/lib/__init__.py
parentdf0b5fb2fb74d1dec39bca6e60b04b49619caf81 (diff)
downloadhyperkitty-ecca23e67b63ef6c9577652a7ea820645a3d9b55.tar.gz
hyperkitty-ecca23e67b63ef6c9577652a7ea820645a3d9b55.tar.xz
hyperkitty-ecca23e67b63ef6c9577652a7ea820645a3d9b55.zip
Add an attachment field to replies and new emails
Diffstat (limited to 'hyperkitty/lib/__init__.py')
-rw-r--r--hyperkitty/lib/__init__.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py
index 0317b92..fbfc38d 100644
--- a/hyperkitty/lib/__init__.py
+++ b/hyperkitty/lib/__init__.py
@@ -105,7 +105,8 @@ def daterange(start_date, end_date):
class PostingFailed(Exception): pass
-def post_to_list(request, mlist, subject, message, headers={}):
+def post_to_list(request, mlist, subject, message, headers={},
+ attachments=None):
if not mlist:
# Make sure the list exists to avoid posting to any email addess
raise SuspiciousOperation("I don't know this mailing-list")
@@ -117,15 +118,25 @@ def post_to_list(request, mlist, subject, message, headers={}):
"your message has not been sent.")
# send the message
headers["User-Agent"] = "HyperKitty on %s" % request.build_absolute_uri("/")
+ if not request.user.first_name and not request.user.last_name:
+ from_email = request.user.email
+ else:
+ from_email = '"%s %s" <%s>' % (request.user.first_name,
+ request.user.last_name,
+ request.user.email)
msg = EmailMessage(
subject=subject,
body=message,
- from_email='"%s %s" <%s>' %
- (request.user.first_name, request.user.last_name,
- request.user.email),
+ from_email=from_email,
to=[mlist.name],
headers=headers,
)
+ # Attachments
+ if attachments:
+ if not isinstance(attachments, list):
+ attachments = [attachments]
+ for attach in attachments:
+ msg.attach(attach.name, attach.read())
msg.send()