+ def add_subject_prefix(self, text):
+ """Given a full-text mail, munge its subject header with the configured
+ subject prefix (if any) and return the updated mail text.
+ """
+ headers, body = self.headers_and_body(text)
+
+ prefix = self.cp.get("list", "subject-prefix")
+
+ # We don't need to do anything special to deal with multi-line
+ # subjects since adding the prefix to the first line of the subject
+ # and leaving the later lines untouched is sufficient.
+ if prefix:
+ has_subject = False
+ for header in headers:
+ if header.startswith('Subject:'):
+ has_subject = True
+ if prefix not in header:
+ text = text.replace(header,
+ header[:9] + prefix + " " + header[9:], 1)
+ break
+ # deal with the case where there was no Subject in the original
+ # mail (broken mailer?)
+ if not has_subject:
+ text = text.replace("\n\n", "Subject: " + prefix + "\n\n", 1)
+
+ return text
+