Lines 143-148
Link Here
|
143 |
{ |
143 |
{ |
144 |
return isspace(ch) || ch == '.' || ch == '-'; |
144 |
return isspace(ch) || ch == '.' || ch == '-'; |
145 |
} |
145 |
} |
|
|
146 |
|
147 |
static void quote_fmt_show_date(const MsgInfo *msginfo, const gchar *format) |
148 |
{ |
149 |
char result[100]; |
150 |
char *rptr; |
151 |
char zone[6]; |
152 |
struct tm lt; |
153 |
const char *fptr; |
154 |
const char *zptr; |
155 |
|
156 |
if (!msginfo->date) |
157 |
return; |
158 |
|
159 |
/* |
160 |
* ALF - GNU C's strftime() has a nice format specifier |
161 |
* for time zone offset (%z). Non-standard however, so |
162 |
* emulate it. |
163 |
*/ |
164 |
|
165 |
#define RLEFT (sizeof result) - (rptr - result) |
166 |
#define STR_SIZE(x) (sizeof (x) - 1) |
167 |
|
168 |
zone[0] = 0; |
169 |
|
170 |
if (procheader_date_parse_to_tm(msginfo->date, <, zone)) { |
171 |
/* |
172 |
* break up format string in tiny bits delimited by valid %z's and |
173 |
* feed it to strftime(). don't forget that '%%z' mean literal '%z'. |
174 |
*/ |
175 |
for (rptr = result, fptr = format; fptr && *fptr && rptr < &result[sizeof result - 1];) { |
176 |
int perc; |
177 |
const char *p; |
178 |
char *tmp; |
179 |
|
180 |
if (NULL != (zptr = strstr(fptr, "%z"))) { |
181 |
/* |
182 |
* count nr. of prepended percent chars |
183 |
*/ |
184 |
for (perc = 0, p = zptr; p && p >= format && *p == '%'; p--, perc++) |
185 |
; |
186 |
/* |
187 |
* feed to strftime() |
188 |
*/ |
189 |
tmp = g_strndup(fptr, zptr - fptr + (perc % 2 ? 0 : STR_SIZE("%z"))); |
190 |
if (tmp) { |
191 |
rptr += strftime(rptr, RLEFT, tmp, <); |
192 |
g_free(tmp); |
193 |
} |
194 |
/* |
195 |
* append time zone offset |
196 |
*/ |
197 |
if (zone[0] && perc % 2) |
198 |
rptr += g_snprintf(rptr, RLEFT, "%s", zone); |
199 |
fptr = zptr + STR_SIZE("%z"); |
200 |
} else { |
201 |
rptr += strftime(rptr, RLEFT, fptr, <); |
202 |
fptr = NULL; |
203 |
} |
204 |
} |
205 |
|
206 |
INSERT(result); |
207 |
} |
208 |
#undef STR_SIZE |
209 |
#undef RLEFT |
210 |
} |
211 |
|
212 |
static void quote_fmt_show_first_name(const MsgInfo *msginfo) |
213 |
{ |
214 |
guchar *p; |
215 |
gchar *str; |
216 |
|
217 |
if (!msginfo->fromname) |
218 |
return; |
219 |
|
220 |
p = strchr(msginfo->fromname, ','); |
221 |
if (p != NULL) { |
222 |
/* fromname is like "Duck, Donald" */ |
223 |
p++; |
224 |
while (*p && isspace(*p)) p++; |
225 |
str = alloca(strlen(p) + 1); |
226 |
if (str != NULL) { |
227 |
strcpy(str, p); |
228 |
INSERT(str); |
229 |
} |
230 |
} else { |
231 |
/* fromname is like "Donald Duck" */ |
232 |
str = alloca(strlen(msginfo->fromname) + 1); |
233 |
if (str != NULL) { |
234 |
strcpy(str, msginfo->fromname); |
235 |
p = str; |
236 |
while (*p && !isspace(*p)) p++; |
237 |
*p = '\0'; |
238 |
INSERT(str); |
239 |
} |
240 |
} |
241 |
} |
242 |
|
243 |
static void quote_fmt_show_last_name(const MsgInfo *msginfo) |
244 |
{ |
245 |
gchar *p; |
246 |
gchar *str; |
247 |
|
248 |
/* This probably won't work together very well with Middle |
249 |
names and the like - thth */ |
250 |
if (!msginfo->fromname) |
251 |
return; |
252 |
|
253 |
str = alloca(strlen(msginfo->fromname) + 1); |
254 |
if (str != NULL) { |
255 |
strcpy(str, msginfo->fromname); |
256 |
p = strchr(str, ','); |
257 |
if (p != NULL) { |
258 |
/* fromname is like "Duck, Donald" */ |
259 |
*p = '\0'; |
260 |
INSERT(str); |
261 |
} else { |
262 |
/* fromname is like "Donald Duck" */ |
263 |
p = str; |
264 |
while (*p && !isspace(*p)) p++; |
265 |
if (*p) { |
266 |
/* We found a space. Get first |
267 |
none-space char and insert |
268 |
rest of string from there. */ |
269 |
while (*p && isspace(*p)) p++; |
270 |
if (*p) { |
271 |
INSERT(p); |
272 |
} else { |
273 |
/* If there is no none-space |
274 |
char, just insert whole |
275 |
fromname. */ |
276 |
INSERT(str); |
277 |
} |
278 |
} else { |
279 |
/* If there is no space, just |
280 |
insert whole fromname. */ |
281 |
INSERT(str); |
282 |
} |
283 |
} |
284 |
} |
285 |
} |
286 |
|
287 |
static void quote_fmt_show_sender_initial(const MsgInfo *msginfo) |
288 |
{ |
289 |
#define MAX_SENDER_INITIAL 20 |
290 |
gchar tmp[MAX_SENDER_INITIAL]; |
291 |
guchar *p; |
292 |
gchar *cur; |
293 |
gint len = 0; |
294 |
|
295 |
if (!msginfo->fromname) |
296 |
return; |
297 |
|
298 |
p = msginfo->fromname; |
299 |
cur = tmp; |
300 |
while (*p) { |
301 |
if (*p && isalnum(*p)) { |
302 |
*cur = toupper(*p); |
303 |
cur++; |
304 |
len++; |
305 |
if (len >= MAX_SENDER_INITIAL - 1) |
306 |
break; |
307 |
} else |
308 |
break; |
309 |
while (*p && !isseparator(*p)) p++; |
310 |
while (*p && isseparator(*p)) p++; |
311 |
} |
312 |
*cur = '\0'; |
313 |
INSERT(tmp); |
314 |
} |
315 |
|
316 |
static void quote_fmt_show_msg(MsgInfo *msginfo, const gchar *body, |
317 |
gboolean quoted, gboolean signature, |
318 |
const gchar *quote_str) |
319 |
{ |
320 |
gchar buf[BUFFSIZE]; |
321 |
FILE *fp; |
322 |
|
323 |
if (!(msginfo->folder || body)) |
324 |
return; |
325 |
|
326 |
if (body) |
327 |
fp = str_open_as_stream(body); |
328 |
else |
329 |
fp = procmime_get_first_text_content(msginfo); |
330 |
|
331 |
if (fp == NULL) |
332 |
g_warning("Can't get text part\n"); |
333 |
else { |
334 |
while (fgets(buf, sizeof(buf), fp) != NULL) { |
335 |
strcrchomp(buf); |
336 |
|
337 |
if (!signature && strncmp(buf, "-- \n", 4) == 0) |
338 |
break; |
339 |
|
340 |
if (quoted && quote_str) |
341 |
INSERT(quote_str); |
342 |
|
343 |
INSERT(buf); |
344 |
} |
345 |
fclose(fp); |
346 |
} |
347 |
} |
348 |
|
349 |
static void quote_fmt_insert_file(const gchar *filename) |
350 |
{ |
351 |
FILE *file; |
352 |
char buffer[256]; |
353 |
|
354 |
if ((file = fopen(filename, "rb")) != NULL) { |
355 |
while (fgets(buffer, sizeof(buffer), file)) { |
356 |
INSERT(buffer); |
357 |
} |
358 |
fclose(file); |
359 |
} |
360 |
|
361 |
} |
362 |
|
363 |
static void quote_fmt_insert_program_output(const gchar *progname) |
364 |
{ |
365 |
FILE *file; |
366 |
char buffer[256]; |
367 |
|
368 |
if ((file = popen(progname, "r")) != NULL) { |
369 |
while (fgets(buffer, sizeof(buffer), file)) { |
370 |
INSERT(buffer); |
371 |
} |
372 |
fclose(file); |
373 |
} |
374 |
} |
375 |
|
146 |
%} |
376 |
%} |
147 |
|
377 |
|
148 |
%union { |
378 |
%union { |
Lines 221-285
Link Here
|
221 |
} |
451 |
} |
222 |
| SHOW_DATE_EXPR OPARENT string CPARENT |
452 |
| SHOW_DATE_EXPR OPARENT string CPARENT |
223 |
{ |
453 |
{ |
224 |
/* |
454 |
quote_fmt_show_date(msginfo, $3); |
225 |
* ALF - GNU C's strftime() has a nice format specifier |
|
|
226 |
* for time zone offset (%z). Non-standard however, so |
227 |
* emulate it. |
228 |
*/ |
229 |
if (msginfo->date) { |
230 |
char result[100]; |
231 |
char *rptr; |
232 |
char zone[6]; |
233 |
struct tm lt; |
234 |
const char *fptr; |
235 |
const char *zptr; |
236 |
|
237 |
#define RLEFT (sizeof result) - (rptr - result) |
238 |
#define STR_SIZE(x) (sizeof (x) - 1) |
239 |
|
240 |
zone[0] = 0; |
241 |
|
242 |
if (procheader_date_parse_to_tm(msginfo->date, <, zone)) { |
243 |
/* |
244 |
* break up format string in tiny bits delimited by valid %z's and |
245 |
* feed it to strftime(). don't forget that '%%z' mean literal '%z'. |
246 |
*/ |
247 |
for (rptr = result, fptr = $3; fptr && *fptr && rptr < &result[sizeof result - 1];) { |
248 |
int perc; |
249 |
const char *p; |
250 |
char *tmp; |
251 |
|
252 |
if (NULL != (zptr = strstr(fptr, "%z"))) { |
253 |
/* |
254 |
* count nr. of prepended percent chars |
255 |
*/ |
256 |
for (perc = 0, p = zptr; p && p >= $3 && *p == '%'; p--, perc++) |
257 |
; |
258 |
/* |
259 |
* feed to strftime() |
260 |
*/ |
261 |
tmp = g_strndup(fptr, zptr - fptr + (perc % 2 ? 0 : STR_SIZE("%z"))); |
262 |
if (tmp) { |
263 |
rptr += strftime(rptr, RLEFT, tmp, <); |
264 |
g_free(tmp); |
265 |
} |
266 |
/* |
267 |
* append time zone offset |
268 |
*/ |
269 |
if (zone[0] && perc % 2) |
270 |
rptr += g_snprintf(rptr, RLEFT, "%s", zone); |
271 |
fptr = zptr + STR_SIZE("%z"); |
272 |
} else { |
273 |
rptr += strftime(rptr, RLEFT, fptr, <); |
274 |
fptr = NULL; |
275 |
} |
276 |
} |
277 |
|
278 |
INSERT(result); |
279 |
} |
280 |
#undef STR_SIZE |
281 |
#undef RLEFT |
282 |
} |
283 |
} |
455 |
} |
284 |
| SHOW_DATE |
456 |
| SHOW_DATE |
285 |
{ |
457 |
{ |
Lines 298-398
Link Here
|
298 |
} |
470 |
} |
299 |
| SHOW_FIRST_NAME |
471 |
| SHOW_FIRST_NAME |
300 |
{ |
472 |
{ |
301 |
if (msginfo->fromname) { |
473 |
quote_fmt_show_first_name(msginfo); |
302 |
guchar *p; |
|
|
303 |
gchar *str; |
304 |
|
305 |
p = strchr(msginfo->fromname, ','); |
306 |
if (p != NULL) { |
307 |
/* fromname is like "Duck, Donald" */ |
308 |
p++; |
309 |
while (*p && isspace(*p)) p++; |
310 |
str = alloca(strlen(p) + 1); |
311 |
if (str != NULL) { |
312 |
strcpy(str, p); |
313 |
INSERT(str); |
314 |
} |
315 |
} else { |
316 |
/* fromname is like "Donald Duck" */ |
317 |
str = alloca(strlen(msginfo->fromname) + 1); |
318 |
if (str != NULL) { |
319 |
strcpy(str, msginfo->fromname); |
320 |
p = str; |
321 |
while (*p && !isspace(*p)) p++; |
322 |
*p = '\0'; |
323 |
INSERT(str); |
324 |
} |
325 |
} |
326 |
} |
327 |
} |
474 |
} |
328 |
| SHOW_LAST_NAME |
475 |
| SHOW_LAST_NAME |
329 |
{ |
476 |
{ |
330 |
/* This probably won't work together very well with Middle |
477 |
quote_fmt_show_last_name(msginfo); |
331 |
names and the like - thth */ |
|
|
332 |
if (msginfo->fromname) { |
333 |
gchar *p; |
334 |
gchar *str; |
335 |
|
336 |
str = alloca(strlen(msginfo->fromname) + 1); |
337 |
if (str != NULL) { |
338 |
strcpy(str, msginfo->fromname); |
339 |
p = strchr(str, ','); |
340 |
if (p != NULL) { |
341 |
/* fromname is like "Duck, Donald" */ |
342 |
*p = '\0'; |
343 |
INSERT(str); |
344 |
} else { |
345 |
/* fromname is like "Donald Duck" */ |
346 |
p = str; |
347 |
while (*p && !isspace(*p)) p++; |
348 |
if (*p) { |
349 |
/* We found a space. Get first |
350 |
none-space char and insert |
351 |
rest of string from there. */ |
352 |
while (*p && isspace(*p)) p++; |
353 |
if (*p) { |
354 |
INSERT(p); |
355 |
} else { |
356 |
/* If there is no none-space |
357 |
char, just insert whole |
358 |
fromname. */ |
359 |
INSERT(str); |
360 |
} |
361 |
} else { |
362 |
/* If there is no space, just |
363 |
insert whole fromname. */ |
364 |
INSERT(str); |
365 |
} |
366 |
} |
367 |
} |
368 |
} |
369 |
} |
478 |
} |
370 |
| SHOW_SENDER_INITIAL |
479 |
| SHOW_SENDER_INITIAL |
371 |
{ |
480 |
{ |
372 |
#define MAX_SENDER_INITIAL 20 |
481 |
quote_fmt_show_sender_initial(msginfo); |
373 |
if (msginfo->fromname) { |
|
|
374 |
gchar tmp[MAX_SENDER_INITIAL]; |
375 |
guchar *p; |
376 |
gchar *cur; |
377 |
gint len = 0; |
378 |
|
379 |
p = msginfo->fromname; |
380 |
cur = tmp; |
381 |
while (*p) { |
382 |
if (*p && isalnum(*p)) { |
383 |
*cur = toupper(*p); |
384 |
cur++; |
385 |
len++; |
386 |
if (len >= MAX_SENDER_INITIAL - 1) |
387 |
break; |
388 |
} else |
389 |
break; |
390 |
while (*p && !isseparator(*p)) p++; |
391 |
while (*p && isseparator(*p)) p++; |
392 |
} |
393 |
*cur = '\0'; |
394 |
INSERT(tmp); |
395 |
} |
396 |
} |
482 |
} |
397 |
| SHOW_SUBJECT |
483 |
| SHOW_SUBJECT |
398 |
{ |
484 |
{ |
Lines 425-523
Link Here
|
425 |
} |
511 |
} |
426 |
| SHOW_MESSAGE |
512 |
| SHOW_MESSAGE |
427 |
{ |
513 |
{ |
428 |
if (msginfo->folder || body) { |
514 |
quote_fmt_show_msg(msginfo, body, FALSE, TRUE, quote_str); |
429 |
gchar buf[BUFFSIZE]; |
|
|
430 |
FILE *fp; |
431 |
|
432 |
if (body) |
433 |
fp = str_open_as_stream(body); |
434 |
else |
435 |
fp = procmime_get_first_text_content(msginfo); |
436 |
|
437 |
if (fp == NULL) |
438 |
g_warning("Can't get text part\n"); |
439 |
else { |
440 |
while (fgets(buf, sizeof(buf), fp) != NULL) { |
441 |
strcrchomp(buf); |
442 |
INSERT(buf); |
443 |
} |
444 |
fclose(fp); |
445 |
} |
446 |
} |
447 |
} |
515 |
} |
448 |
| SHOW_QUOTED_MESSAGE |
516 |
| SHOW_QUOTED_MESSAGE |
449 |
{ |
517 |
{ |
450 |
if (msginfo->folder || body) { |
518 |
quote_fmt_show_msg(msginfo, body, TRUE, TRUE, quote_str); |
451 |
gchar buf[BUFFSIZE]; |
|
|
452 |
FILE *fp; |
453 |
|
454 |
if (body) |
455 |
fp = str_open_as_stream(body); |
456 |
else |
457 |
fp = procmime_get_first_text_content(msginfo); |
458 |
|
459 |
if (fp == NULL) |
460 |
g_warning("Can't get text part\n"); |
461 |
else { |
462 |
while (fgets(buf, sizeof(buf), fp) != NULL) { |
463 |
strcrchomp(buf); |
464 |
if (quote_str) |
465 |
INSERT(quote_str); |
466 |
INSERT(buf); |
467 |
} |
468 |
fclose(fp); |
469 |
} |
470 |
} |
471 |
} |
519 |
} |
472 |
| SHOW_MESSAGE_NO_SIGNATURE |
520 |
| SHOW_MESSAGE_NO_SIGNATURE |
473 |
{ |
521 |
{ |
474 |
if (msginfo->folder || body) { |
522 |
quote_fmt_show_msg(msginfo, body, FALSE, FALSE, quote_str); |
475 |
gchar buf[BUFFSIZE]; |
|
|
476 |
FILE *fp; |
477 |
|
478 |
if (body) |
479 |
fp = str_open_as_stream(body); |
480 |
else |
481 |
fp = procmime_get_first_text_content(msginfo); |
482 |
|
483 |
if (fp == NULL) |
484 |
g_warning("Can't get text part\n"); |
485 |
else { |
486 |
while (fgets(buf, sizeof(buf), fp) != NULL) { |
487 |
strcrchomp(buf); |
488 |
if (strncmp(buf, "-- \n", 4) == 0) |
489 |
break; |
490 |
INSERT(buf); |
491 |
} |
492 |
fclose(fp); |
493 |
} |
494 |
} |
495 |
} |
523 |
} |
496 |
| SHOW_QUOTED_MESSAGE_NO_SIGNATURE |
524 |
| SHOW_QUOTED_MESSAGE_NO_SIGNATURE |
497 |
{ |
525 |
{ |
498 |
if (msginfo->folder || body) { |
526 |
quote_fmt_show_msg(msginfo, body, TRUE, FALSE, quote_str); |
499 |
gchar buf[BUFFSIZE]; |
|
|
500 |
FILE *fp; |
501 |
|
502 |
if (body) |
503 |
fp = str_open_as_stream(body); |
504 |
else |
505 |
fp = procmime_get_first_text_content(msginfo); |
506 |
|
507 |
if (fp == NULL) |
508 |
g_warning("Can't get text part\n"); |
509 |
else { |
510 |
while (fgets(buf, sizeof(buf), fp) != NULL) { |
511 |
strcrchomp(buf); |
512 |
if (strncmp(buf, "-- \n", 4) == 0) |
513 |
break; |
514 |
if (quote_str) |
515 |
INSERT(quote_str); |
516 |
INSERT(buf); |
517 |
} |
518 |
fclose(fp); |
519 |
} |
520 |
} |
521 |
} |
527 |
} |
522 |
| SHOW_BACKSLASH |
528 |
| SHOW_BACKSLASH |
523 |
{ |
529 |
{ |
Lines 629-657
Link Here
|
629 |
insert: |
635 |
insert: |
630 |
INSERT_FILE OPARENT string CPARENT |
636 |
INSERT_FILE OPARENT string CPARENT |
631 |
{ |
637 |
{ |
632 |
{ |
638 |
quote_fmt_insert_file($3); |
633 |
FILE *file; |
|
|
634 |
char buffer[256]; |
635 |
|
636 |
if((file = fopen($3, "rb")) != NULL) { |
637 |
while(fgets(buffer, sizeof(buffer), file)) { |
638 |
INSERT(buffer); |
639 |
} |
640 |
fclose(file); |
641 |
} |
642 |
} |
643 |
} |
639 |
} |
644 |
| INSERT_PROGRAMOUTPUT OPARENT string CPARENT |
640 |
| INSERT_PROGRAMOUTPUT OPARENT string CPARENT |
645 |
{ |
641 |
{ |
646 |
{ |
642 |
quote_fmt_insert_program_output($3); |
647 |
FILE *file; |
|
|
648 |
char buffer[256]; |
649 |
|
650 |
if((file = popen($3, "r")) != NULL) { |
651 |
while(fgets(buffer, sizeof(buffer), file)) { |
652 |
INSERT(buffer); |
653 |
} |
654 |
fclose(file); |
655 |
} |
656 |
} |
657 |
}; |
643 |
}; |