Skip to content

Commit 8ecc243

Browse files
#1369 try to guess if file is an image
1 parent d9d75a7 commit 8ecc243

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sarracenia/flowcb/send/email.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from email.mime.multipart import MIMEMultipart
6262
from email.mime.application import MIMEApplication
6363
from email.mime.text import MIMEText
64+
import mimetypes
6465
import logging
6566
import os.path
6667
import re
@@ -146,10 +147,12 @@ def send(self, msg):
146147
# Get list of recipients for this message, from the mask that matched the filename/path
147148
recipients = self.o.masks[msg['_mask_index']][-1]
148149

150+
file_type = mimetypes.guess_type(ipath)
151+
149152
# Prepare the email message
150153
try:
151-
if self.o.email_attachment:
152-
# Build a non-text email message for the attachment.
154+
# Build a non-text email message for the attachment if specified or if the file type can be deemed to be an image.
155+
if self.o.email_attachment or 'image' in file_type[0]:
153156
emsg = MIMEMultipart()
154157
emsg_text = MIMEText(f"{self.o.email_attachment_text}")
155158
# Add the attachment text that will be paired with the attachment data

0 commit comments

Comments
 (0)