From 69c31c492444ba1bb742eb9f34e0c0299972cf6a Mon Sep 17 00:00:00 2001
From: Richard Frith-MacDonald
The Email array lists email addresses to which email alerts are
* to be sent.
- * An optional 'Subject' field may be present in the rule ... this is used
- * to specify that the is to be tagged with the given subject line. This
- * defeats batching of messages in that only messages with the
- * same subject may be batched in the same email.
+ * An optional Subject field may be present in the rule ...
+ * this is used to specify that the is to be tagged with the given
+ * subject line. This defeats batching of messages in that
+ * only messages with the same subject may be batched in the same email.
+ * NB. The value of the Subject field is used as a template
+ * in the same way as the Replacement fields.
*
Configuration of the alerter is done by the 'Alerter' key in the user diff --git a/EcAlerter.m b/EcAlerter.m index 9189aca..609f68e 100644 --- a/EcAlerter.m +++ b/EcAlerter.m @@ -98,11 +98,11 @@ @end static NSMutableString * -replaceFields(NSDictionary *fields) +replaceFields(NSDictionary *fields, NSString *template) { NSMutableString *m; - m = [[[fields objectForKey: @"Replacement"] mutableCopy] autorelease]; + m = [[template mutableCopy] autorelease]; if (nil != m) { NSEnumerator *e; @@ -541,8 +541,7 @@ replaceFields(NSDictionary *fields) s = [d objectForKey: @"Rewrite"]; if (nil != s) { - [m setObject: s forKey: @"Replacement"]; - s = replaceFields(m); + s = replaceFields(m, s); [m setObject: s forKey: @"Message"]; } @@ -816,7 +815,7 @@ replaceFields(NSDictionary *fields) /* * Perform {field-name} substitutions ... */ - s = replaceFields(m); + s = replaceFields(m, [m objectForKey: @"Replacement"]); while ((d = [e nextObject]) != nil) { [[EcProc cmdLogFile: d] printf: @"%@\n", s]; @@ -838,6 +837,11 @@ replaceFields(NSDictionary *fields) NSString *text; NSString *subject; + /* + * Perform {field-name} substitutions ... + */ + text = replaceFields(m, [m objectForKey: @"Replacement"]); + subject = [m objectForKey: @"Subject"]; if (nil == subject) { @@ -859,15 +863,10 @@ replaceFields(NSDictionary *fields) } else { - AUTORELEASE(RETAIN(subject)); + subject = replaceFields(m, subject); [m removeObjectForKey: @"Subject"]; } - /* - * Perform {field-name} substitutions ... - */ - text = replaceFields(m); - /* If we need to send immediately, don't buffer the message. */ if (nil != identifier) @@ -996,7 +995,7 @@ replaceFields(NSDictionary *fields) */ t = RETAIN([m objectForKey: @"Timestamp"]); [m removeObjectForKey: @"Timestamp"]; - s = replaceFields(m); + s = replaceFields(m, [m objectForKey: @"Replacement"]); if (t != nil) { [m setObject: t forKey: @"Timestamp"];