Skip to content

Commit

Permalink
Merge branch 'development' into development_py36
Browse files Browse the repository at this point in the history
  • Loading branch information
petersilva committed Jan 23, 2025
2 parents 6cc71bd + 3e1ccc0 commit 38ebfa8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
15 changes: 8 additions & 7 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
metpx-sr3 (3.00.57rc2) UNRELEASED; urgency=medium
metpx-sr3 (3.00.58rc1) UNRELEASED; urgency=medium

* #1369 try to guess if file is an image

-- Reid Sunderland <[email protected]> Mon, 20 Jan 2025 16:32:59 +0000

metpx-sr3 (3.00.57) unstable; urgency=medium

* fix #1366 ln -sf a b ... leave tmp file when a does not exist.
* fix #1365 better error handling when makedirs fail.
* fix #1363 hardlink support broken.
* fix #1358 status displays of intervals over 1 month causes crashes.
* fix #1351 download with arbitrary checksum.
* progress #1297 hard ordering of operations (still some use cases left.)

-- peter <[email protected]> Mon, 23 Dec 2024 00:56:15 -0500

metpx-sr3 (3.00.57rc1) unstable; urgency=medium

* New #1350 Add "down" and "disconnected" run states to sr3 status
* New #1323 DESTFN=NONE::TIME now works.
* New #1299 after_gather entry point added.
Expand Down Expand Up @@ -42,7 +43,7 @@ metpx-sr3 (3.00.57rc1) unstable; urgency=medium
* fix #1241 sr3 status more compact.
* fix #1206 exclude retries from lag calculation.

-- SSC-5CD2310S60 <[email protected]> Tue, 06 Dec 2024 16:42:09 -0500
-- Reid Sunderland <[email protected]> Mon, 20 Jan 2025 09:38:09 -0600

metpx-sr3 (3.00.56) unstable; urgency=medium

Expand Down
2 changes: 1 addition & 1 deletion sarracenia/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.00.57rc2"
__version__ = "3.00.58rc1"
37 changes: 33 additions & 4 deletions sarracenia/flowcb/send/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,26 @@
email_subject_prepend Sent by Sarracenia:
There is also the option of sending a file as an attachment instead of embedding its contents in the email.
To do this, there are two options that can be used.
`` email_attachment `` is a boolean value to specify if you want to send files as attachments
`` email_attachment_text `` is the optional text that can be added inside of the email content, with the attached file.
email_attachment True
email_attachment_text Attached in this email is data coming from XXX
Future Improvement Ideas:
- SMTP on different ports and with authentication
- Attach the file instead of putting the contents in the body (useful for binary files)
Original Author: Wahaj Taseer - June, 2019
"""

from email.message import EmailMessage
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from email.mime.text import MIMEText
import mimetypes
import logging
import os.path
import re
Expand All @@ -65,6 +77,8 @@ def __init__(self, options):
super().__init__(options,logger)
self.o.add_option('email_from', 'str', default_value='')
self.o.add_option('email_subject_prepend', 'str', default_value='')
self.o.add_option('email_attachment', 'flag', default_value=False)
self.o.add_option('email_attachment_text', 'str', default_value='')

# Parse accept/reject mask arguments into email recipient lists
try:
Expand Down Expand Up @@ -133,13 +147,28 @@ def send(self, msg):
# Get list of recipients for this message, from the mask that matched the filename/path
recipients = self.o.masks[msg['_mask_index']][-1]

file_type = mimetypes.guess_type(ipath)

# Prepare the email message
emsg = EmailMessage()
try:
with open(ipath) as fp:
emsg.set_content(fp.read())
# Build a non-text email message for the attachment if specified or if the file type can be deemed to be an image.
if self.o.email_attachment or 'image' in file_type[0]:
emsg = MIMEMultipart()
emsg_text = MIMEText(f"{self.o.email_attachment_text}")
# Add the attachment text that will be paired with the attachment data
emsg.attach(emsg_text)
with open(ipath, 'rb') as fp:
attachment_data = fp.read()
attachment = MIMEApplication(attachment_data, name=os.path.basename(ipath))
# Add the attachment data to the email
emsg.attach(attachment)
else:
emsg = EmailMessage()
with open(ipath) as fp:
emsg.set_content(fp.read())
except Exception as e:
logger.error(f"Failed to read {ipath}, can't send to {recipients}")
logger.debug('Exception details:', exc_info=True)
# No retry if the file doesn't exist
return -1

Expand Down
6 changes: 5 additions & 1 deletion sarracenia/moth/amqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ def __connect(self, broker) -> bool:
broker.url.password),
login_method=broker.login_method,
virtual_host=vhost,
ssl=(broker.url.scheme[-1] == 's'))
ssl=(broker.url.scheme[-1] == 's'),
client_properties={'product':'MetPX Sarracenia (sr3)',
'product_version':sarracenia.__version__,
}
)
self.connection_id = str(uuid.uuid4()) + ("_sub" if self.is_subscriber else "_pub")
self.broker = host + '/' + vhost
if hasattr(self.connection, 'connect'):
Expand Down

0 comments on commit 38ebfa8

Please sign in to comment.