]> git.parisson.com Git - teleforma.git/commitdiff
More robust handling of errors and too long subjects dev
authorGael Le Mignot <gael@pilotsystems.net>
Tue, 24 Jun 2025 07:46:58 +0000 (09:46 +0200)
committerGael Le Mignot <gael@pilotsystems.net>
Tue, 24 Jun 2025 07:46:58 +0000 (09:46 +0200)
teleforma/management/commands/teleforma-get-postman-replies.py

index af8e8a182b1ab39195b8aaaa55442610e61b0428..66568bb494242fe76f10ded4a44148268e194478 100644 (file)
@@ -23,7 +23,7 @@ def decode_header(header, charset):
     res = []
     for value, encoding in header:
         if isinstance(value, bytes):
-            value = value.decode(encoding)
+            value = value.decode(encoding or charset)
         res.append(value)
     return " ".join(res)
 
@@ -118,6 +118,9 @@ class Command(BaseCommand):
         if not msg.thread:
             msg.thread = msg
             msg.save()
+
+        if len(subject) > 200:
+            subject = subject[:200] + "..."
         
         mess = Message(sender = msg.recipient, recipient = msg.sender,
                        subject = subject, body = body, thread = msg.thread,
@@ -148,8 +151,8 @@ class Command(BaseCommand):
                     self.process(msg)
                     pop.dele(msgid)
                 except Exception as e:
-                    self.logger.warning("Error in message %s: %s" % (msgid, str(e)))
-                    raise
+                    self.logger.warning("Error in message %s: %s" % (msgid, str(e)),
+                                        exc_info = e)
         finally:
             pop.quit()