49 |
|
|
50 |
|
|
51 |
static void copy_mail(Mail_T, Mail_T); |
static void copy_mail(Mail_T, Mail_T); |
52 |
static int count(char *, const char *); |
static void replace_bare_linefeed(Mail_T *); |
|
static void replace(char **, const char *, const char *); |
|
53 |
static void substitute(Mail_T*, char *name, const char *event); |
static void substitute(Mail_T*, char *name, const char *event); |
54 |
|
|
55 |
|
|
95 |
|
|
96 |
copy_mail(tmp, m); |
copy_mail(tmp, m); |
97 |
|
|
98 |
tmp->opt_message= Event_get_message(E); |
if(Event_get_message(E)) { |
99 |
|
tmp->opt_message= xstrdup(Event_get_message(E)); |
100 |
|
} |
101 |
|
|
102 |
substitute(&tmp, s->name, EVENT_DESCRIPTION(E)); |
substitute(&tmp, s->name, EVENT_DESCRIPTION(E)); |
103 |
|
|
104 |
|
replace_bare_linefeed(&tmp); |
105 |
|
|
106 |
tmp->next= list; |
tmp->next= list; |
107 |
list= tmp; |
list= tmp; |
108 |
|
|
134 |
|
|
135 |
ASSERT(m && name && event); |
ASSERT(m && name && event); |
136 |
|
|
137 |
replace(&(*m)->from, "$HOST", host); |
replace_string(&(*m)->from, "$HOST", host); |
138 |
replace(&(*m)->subject, "$DATE", now); |
replace_string(&(*m)->subject, "$DATE", now); |
139 |
replace(&(*m)->message, "$DATE", now); |
replace_string(&(*m)->message, "$DATE", now); |
140 |
replace(&(*m)->subject, "$HOST", host); |
replace_string(&(*m)->subject, "$HOST", host); |
141 |
replace(&(*m)->message, "$HOST", host); |
replace_string(&(*m)->message, "$HOST", host); |
142 |
replace(&(*m)->subject, "$PROGRAM", name); |
replace_string(&(*m)->subject, "$PROGRAM", name); |
143 |
replace(&(*m)->message, "$PROGRAM", name); |
replace_string(&(*m)->message, "$PROGRAM", name); |
144 |
replace(&(*m)->subject, "$SERVICE", name); |
replace_string(&(*m)->subject, "$SERVICE", name); |
145 |
replace(&(*m)->message, "$SERVICE", name); |
replace_string(&(*m)->message, "$SERVICE", name); |
146 |
replace(&(*m)->subject, "$EVENT", event); |
replace_string(&(*m)->subject, "$EVENT", event); |
147 |
replace(&(*m)->message, "$EVENT", event); |
replace_string(&(*m)->message, "$EVENT", event); |
148 |
|
|
149 |
free(now); |
free(now); |
150 |
free(host); |
free(host); |
152 |
} |
} |
153 |
|
|
154 |
|
|
|
static void replace(char **src, const char *old, const char *new) { |
|
|
|
|
|
int i; |
|
|
int d; |
|
|
|
|
|
ASSERT(src && old && new); |
|
|
|
|
|
i= count(*src, old); |
|
|
d= strlen(new)-strlen(old); |
|
|
|
|
|
if(i==0) |
|
|
return; |
|
|
if(d>0) |
|
|
d*= i; |
|
|
else |
|
|
d= 0; |
|
|
|
|
|
{ |
|
|
char *p, *q; |
|
|
int l= strlen(old); |
|
|
char buf[strlen(*src)+d+1]; |
|
|
|
|
|
q= *src; |
|
|
*buf= '\0'; |
|
|
|
|
|
while((p= strstr(q, old))) { |
|
|
|
|
|
*p= '\0'; |
|
|
strcat(buf, q); |
|
|
strcat(buf, new); |
|
|
p+= l; |
|
|
q= p; |
|
|
|
|
|
} |
|
|
|
|
|
strcat(buf, q); |
|
|
free(*src); |
|
|
*src= xstrdup(buf); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static int count(char *src, const char *needle) { |
|
|
|
|
|
int i= 0; |
|
|
char *p= src; |
|
|
|
|
|
ASSERT(src && needle); |
|
|
|
|
|
while((p= strstr(p, needle))) { i++; p++; } |
|
|
|
|
|
return i; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
155 |
static void copy_mail(Mail_T n, Mail_T o) { |
static void copy_mail(Mail_T n, Mail_T o) { |
156 |
|
|
157 |
ASSERT(n && o); |
ASSERT(n && o); |
179 |
|
|
180 |
} |
} |
181 |
|
|
182 |
|
|
183 |
|
static void replace_bare_linefeed(Mail_T *m) { |
184 |
|
|
185 |
|
replace_string(&(*m)->message, "\r\n", "\n"); |
186 |
|
replace_string(&(*m)->message, "\n", "\r\n"); |
187 |
|
if((*m)->opt_message) { |
188 |
|
replace_string(&(*m)->opt_message, "\r\n", "\n"); |
189 |
|
replace_string(&(*m)->opt_message, "\n", "\r\n"); |
190 |
|
} |
191 |
|
|
192 |
|
} |