27 |
if (argc > 1) |
if (argc > 1) |
28 |
return util_msglist_command (mail_from, argc, argv, 0); |
return util_msglist_command (mail_from, argc, argv, 0); |
29 |
else |
else |
30 |
{ |
return mail_from0 (cursor, 1); |
31 |
message_t msg; |
return 1; |
32 |
header_t hdr = NULL; |
} |
|
envelope_t env; |
|
|
attribute_t attr; |
|
|
char *from = NULL, *subj = NULL, *fromp, *subjp; |
|
|
int froml, subjl; |
|
|
char date[80], st[10]; |
|
|
int cols = util_getcols () - 6; |
|
|
int cflag; |
|
|
size_t m_size = 0, m_lines = 0; |
|
|
const char *p; |
|
|
struct tm tm; |
|
|
mu_timezone tz; |
|
33 |
|
|
34 |
if (util_get_message (mbox, cursor, &msg, 1)) |
int |
35 |
return 1; |
mail_from0 (int msgno, int verbose) |
36 |
|
{ |
37 |
|
message_t msg; |
38 |
|
header_t hdr = NULL; |
39 |
|
envelope_t env; |
40 |
|
attribute_t attr; |
41 |
|
char *from = NULL, *subj = NULL, *fromp, *subjp; |
42 |
|
int froml, subjl; |
43 |
|
char date[80], st[10]; |
44 |
|
int cols = util_getcols () - 6; |
45 |
|
int cflag; |
46 |
|
size_t m_size = 0, m_lines = 0; |
47 |
|
const char *p; |
48 |
|
struct tm tm; |
49 |
|
mu_timezone tz; |
50 |
|
|
51 |
|
if (util_get_message (mbox, msgno, &msg, |
52 |
|
MSG_NODELETED|(verbose ? 0 : MSG_SILENT))) |
53 |
|
return 1; |
54 |
|
|
55 |
message_get_header (msg, &hdr); |
message_get_header (msg, &hdr); |
56 |
if (header_aget_value (hdr, MU_HEADER_FROM, &from) == 0) |
if (header_aget_value (hdr, MU_HEADER_FROM, &from) == 0) |
57 |
|
{ |
58 |
|
address_t address = NULL; |
59 |
|
if (address_create (&address, from) == 0) |
60 |
{ |
{ |
61 |
address_t address = NULL; |
char name[128]; |
62 |
if (address_create (&address, from) == 0) |
size_t len = strlen (from); |
63 |
|
*name = '\0'; |
64 |
|
address_get_personal (address, 1, name, sizeof name, NULL); |
65 |
|
if (*name && len) |
66 |
{ |
{ |
67 |
char name[128]; |
strncpy (from, name, len - 1); |
68 |
size_t len = strlen (from); |
from[len - 1] = '\0'; |
|
*name = '\0'; |
|
|
address_get_personal (address, 1, name, sizeof name, NULL); |
|
|
if (*name && len) |
|
|
{ |
|
|
strncpy (from, name, len - 1); |
|
|
from[len - 1] = '\0'; |
|
|
} |
|
|
else |
|
|
address_get_email (address, 1, from, strlen (from), NULL); |
|
|
address_destroy (&address); |
|
69 |
} |
} |
70 |
|
else |
71 |
|
address_get_email (address, 1, from, strlen (from), NULL); |
72 |
|
address_destroy (&address); |
73 |
} |
} |
|
header_aget_value (hdr, MU_HEADER_SUBJECT, &subj); |
|
|
|
|
|
message_get_attribute (msg, &attr); |
|
|
|
|
|
if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_MBOXED)) |
|
|
cflag = 'M'; |
|
|
else if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_SAVED)) |
|
|
cflag = '*'; |
|
|
else if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_TAGGED)) |
|
|
cflag = 'T'; |
|
|
else if (attribute_is_read (attr)) |
|
|
cflag = 'R'; |
|
|
else if (attribute_is_seen (attr)) |
|
|
cflag = 'U'; |
|
|
else if (attribute_is_recent(attr)) |
|
|
cflag = 'N'; |
|
|
else |
|
|
cflag = ' '; |
|
|
|
|
|
message_get_envelope (msg, &env); |
|
|
envelope_date (env, date, sizeof (date), NULL); |
|
|
p = date; |
|
|
if (mu_parse_ctime_date_time(&p, &tm, &tz) == 0) |
|
|
strftime (date, sizeof(date), "%a %b %e %H:%M", &tm); |
|
|
|
|
|
message_size (msg, &m_size); |
|
|
message_lines (msg, &m_lines); |
|
|
|
|
|
snprintf (st, sizeof(st), "%3d/%-5d", m_lines, m_size); |
|
|
|
|
|
/* The "From" field will take a third of the screen. |
|
|
Subject will take the rest. |
|
|
FIXME: This is not quite correct that we use fixed sizes |
|
|
18, 16 for the other fields. |
|
|
*/ |
|
|
froml = cols / 3; |
|
|
subjl = cols - froml - strlen (st) - strlen (date); |
|
|
|
|
|
fromp = from ? from : ""; |
|
|
subjp = subj ? subj : fromp; |
|
|
fprintf (ofile, "%c%c%4d %-18.18s %-16.16s %s %.*s\n", |
|
|
cursor == realcursor ? '>' : ' ', cflag, cursor, |
|
|
fromp, date, st, (subjl < 0) ? 0 : subjl, subjp); |
|
|
|
|
|
free (from); |
|
|
free (subj); |
|
|
|
|
|
return 0; |
|
74 |
} |
} |
75 |
return 1; |
header_aget_value (hdr, MU_HEADER_SUBJECT, &subj); |
76 |
|
|
77 |
|
message_get_attribute (msg, &attr); |
78 |
|
|
79 |
|
if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_MBOXED)) |
80 |
|
cflag = 'M'; |
81 |
|
else if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_SAVED)) |
82 |
|
cflag = '*'; |
83 |
|
else if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_TAGGED)) |
84 |
|
cflag = 'T'; |
85 |
|
else if (attribute_is_read (attr)) |
86 |
|
cflag = 'R'; |
87 |
|
else if (attribute_is_seen (attr)) |
88 |
|
cflag = 'U'; |
89 |
|
else if (attribute_is_recent(attr)) |
90 |
|
cflag = 'N'; |
91 |
|
else |
92 |
|
cflag = ' '; |
93 |
|
|
94 |
|
message_get_envelope (msg, &env); |
95 |
|
envelope_date (env, date, sizeof (date), NULL); |
96 |
|
p = date; |
97 |
|
if (mu_parse_ctime_date_time(&p, &tm, &tz) == 0) |
98 |
|
strftime (date, sizeof(date), "%a %b %e %H:%M", &tm); |
99 |
|
|
100 |
|
message_size (msg, &m_size); |
101 |
|
message_lines (msg, &m_lines); |
102 |
|
|
103 |
|
snprintf (st, sizeof(st), "%3d/%-5d", m_lines, m_size); |
104 |
|
|
105 |
|
/* The "From" field will take a third of the screen. |
106 |
|
Subject will take the rest. |
107 |
|
FIXME: This is not quite correct that we use fixed sizes |
108 |
|
18, 16 for the other fields. |
109 |
|
*/ |
110 |
|
froml = cols / 3; |
111 |
|
subjl = cols - froml - strlen (st) - strlen (date); |
112 |
|
|
113 |
|
fromp = from ? from : ""; |
114 |
|
subjp = subj ? subj : fromp; |
115 |
|
fprintf (ofile, "%c%c%4d %-18.18s %-16.16s %s %.*s\n", |
116 |
|
msgno == realcursor ? '>' : ' ', cflag, msgno, |
117 |
|
fromp, date, st, (subjl < 0) ? 0 : subjl, subjp); |
118 |
|
|
119 |
|
free (from); |
120 |
|
free (subj); |
121 |
|
|
122 |
|
return 0; |
123 |
} |
} |