Call run_user_action instead of dumping message contents to user's tty
Showing
1 changed file
with
4 additions
and
58 deletions
... | @@ -17,15 +17,6 @@ | ... | @@ -17,15 +17,6 @@ |
17 | 17 | ||
18 | #include "comsat.h" | 18 | #include "comsat.h" |
19 | 19 | ||
20 | #include <mailutils/mailbox.h> | ||
21 | #include <mailutils/message.h> | ||
22 | #include <mailutils/header.h> | ||
23 | #include <mailutils/body.h> | ||
24 | #include <mailutils/registrar.h> | ||
25 | #include <mailutils/stream.h> | ||
26 | #include <mailutils/mutil.h> | ||
27 | #include <mailutils/error.h> | ||
28 | |||
29 | #define IMPL "GNU Comsat Daemon" | 20 | #define IMPL "GNU Comsat Daemon" |
30 | 21 | ||
31 | #ifndef PATH_DEV | 22 | #ifndef PATH_DEV |
... | @@ -85,6 +76,7 @@ int port = 512; /* Default biff port */ | ... | @@ -85,6 +76,7 @@ int port = 512; /* Default biff port */ |
85 | int timeout = 0; | 76 | int timeout = 0; |
86 | int maxlines = 5; | 77 | int maxlines = 5; |
87 | char hostname[MAXHOSTNAMELEN]; | 78 | char hostname[MAXHOSTNAMELEN]; |
79 | char *username; | ||
88 | 80 | ||
89 | static void comsat_init (void); | 81 | static void comsat_init (void); |
90 | static void comsat_daemon_init (void); | 82 | static void comsat_daemon_init (void); |
... | @@ -453,7 +445,6 @@ notify_user (char *user, char *device, char *path, off_t offset) | ... | @@ -453,7 +445,6 @@ notify_user (char *user, char *device, char *path, off_t offset) |
453 | stream_t stream = NULL; | 445 | stream_t stream = NULL; |
454 | int status; | 446 | int status; |
455 | size_t size, count, n; | 447 | size_t size, count, n; |
456 | int nlines; | ||
457 | 448 | ||
458 | change_user (user); | 449 | change_user (user); |
459 | if ((fp = fopen (device, "w")) == NULL) | 450 | if ((fp = fopen (device, "w")) == NULL) |
... | @@ -464,9 +455,6 @@ notify_user (char *user, char *device, char *path, off_t offset) | ... | @@ -464,9 +455,6 @@ notify_user (char *user, char *device, char *path, off_t offset) |
464 | 455 | ||
465 | cr = get_newline_str (fp); | 456 | cr = get_newline_str (fp); |
466 | 457 | ||
467 | fprintf(fp, "%s\aNew mail for %s@%s\a has arrived:%s----%s", | ||
468 | cr, user, hostname, cr, cr); | ||
469 | |||
470 | if (!path) | 458 | if (!path) |
471 | { | 459 | { |
472 | path = mailbox_path (user); | 460 | path = mailbox_path (user); |
... | @@ -527,51 +515,7 @@ notify_user (char *user, char *device, char *path, off_t offset) | ... | @@ -527,51 +515,7 @@ notify_user (char *user, char *device, char *path, off_t offset) |
527 | mailbox_messages_count (tmp, &count); | 515 | mailbox_messages_count (tmp, &count); |
528 | mailbox_get_message (tmp, 1, &msg); | 516 | mailbox_get_message (tmp, 1, &msg); |
529 | 517 | ||
530 | if ((status = message_get_header (msg, &header))) | 518 | run_user_action (fp, cr, msg); |
531 | { | ||
532 | syslog (LOG_ERR, "can't get header: %s", strerror (status)); | ||
533 | return; | ||
534 | } | ||
535 | |||
536 | /* Take care to clear eighth bit, so we won't upset some stupid terminals */ | ||
537 | #define LB(c) ((c)&0x7f) | ||
538 | |||
539 | nlines = maxlines; | ||
540 | if (header_aget_value (header, MU_HEADER_FROM, &p) == 0) | ||
541 | { | ||
542 | fprintf (fp, "From: "); | ||
543 | for (; *p; p++) | ||
544 | fputc (LB (*p), fp); | ||
545 | fprintf (fp, cr); | ||
546 | if (nlines-- == 0) | ||
547 | return; | ||
548 | } | ||
549 | |||
550 | if (header_aget_value (header, MU_HEADER_SUBJECT, &p) == 0) | ||
551 | { | ||
552 | fprintf (fp, "Subject: "); | ||
553 | for (; *p; p++) | ||
554 | fputc (LB (*p), fp); | ||
555 | fprintf (fp, cr); | ||
556 | if (nlines-- == 0) | ||
557 | return; | ||
558 | } | ||
559 | |||
560 | message_get_body (msg, &body); | ||
561 | body_get_stream (body, &stream); | ||
562 | stream_read (stream, blurb, size, 0, &n); | ||
563 | blurb[n] = 0; | ||
564 | |||
565 | for (p = blurb; *p && nlines-- > 0; ) | ||
566 | { | ||
567 | while (*p && *p == '\n') | ||
568 | p++; | ||
569 | for (; *p && *p != '\n'; p++) | ||
570 | fputc (LB (*p), fp); | ||
571 | fprintf (fp, cr); | ||
572 | } | ||
573 | |||
574 | fprintf (fp, "----%s", cr); | ||
575 | fclose (fp); | 519 | fclose (fp); |
576 | } | 520 | } |
577 | 521 | ||
... | @@ -655,6 +599,8 @@ change_user (char *user) | ... | @@ -655,6 +599,8 @@ change_user (char *user) |
655 | 599 | ||
656 | setgid (pw->pw_gid); | 600 | setgid (pw->pw_gid); |
657 | setuid (pw->pw_uid); | 601 | setuid (pw->pw_uid); |
602 | chdir (pw->pw_dir); | ||
603 | username = user; | ||
658 | } | 604 | } |
659 | 605 | ||
660 | void | 606 | void | ... | ... |
-
Please register or sign in to post a comment