Terminate if the tty is gone
[infodrom/newmail] / output.c
1 /*
2     Copyright (c) 2004  Joey Schulze <joey@infodrom.org>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 /*
20     From Elm 2.4pl25ME+43:
21
22     The output format is either:
23
24           newmail:
25              >> New mail from <user> - <subject>
26              >> Priority mail from <user> - <subject>
27
28              >> <folder>: from <user> - <subject>
29              >> <folder>: Priority from <user> - <subject>
30
31           newmail -w:
32              <user> - <subject>
33              Priority: <user> - <subject>
34
35              <folder>: <user> - <subject>
36              <folder>: Priority: <user> - <subject>
37
38  */
39
40 #include <stdio.h>
41 #include "rfc2047.h"
42 #include "optdefs.h"
43
44 #define MAIL_FROM       "Mail from"
45 #define PRIO_FROM       "Priority mail from"
46 #define PRIO_WIN        "Priority"
47
48 void emit(char *prefix, char *realname, char *subject, int priority, int opt_flags)
49 {
50   if (!(opt_flags & OPT_RAW)) {
51     realname = convert_header (realname);
52     subject = convert_header (subject);
53   }
54
55   if (opt_flags & OPT_WINDOW) {
56     if (prefix != NULL)
57       printf ("%s: ", prefix);
58     if (priority)
59       printf ("%s: ", PRIO_WIN);
60     printf ("%s - %s\n", realname, subject);
61   } else {
62     printf ("\r>> ");
63     if (prefix != NULL)
64       printf ("%s: ", prefix);
65
66       if (priority)
67         printf ("%s %s - %s\n", PRIO_FROM, realname, subject);
68       else
69         printf ("%s %s - %s\n", MAIL_FROM, realname, subject);
70   }
71 }