Commit a273efe0 a273efe0a7716b83b3561ba69bb837c6a7f11b96 by Alain Magloire

* mail/from.c: Use address_get_personal() for a more

	pretty print when showing the headers.
1 parent 8cc9f7db
1 2001-06-26 Alain Magloire
2
3 * mail/from.c: Use address_get_personal() for a more
4 pretty print when showing the headers.
5
6
1 2001-06-26 Sergey Poznyakoff 7 2001-06-26 Sergey Poznyakoff
2 * mail/util.c: 8 * mail/util.c:
3 Added extra argument to util_msglist_command(), controlling 9 Added extra argument to util_msglist_command(), controlling
......
...@@ -29,10 +29,10 @@ mail_from (int argc, char **argv) ...@@ -29,10 +29,10 @@ mail_from (int argc, char **argv)
29 else 29 else
30 { 30 {
31 message_t msg; 31 message_t msg;
32 header_t hdr; 32 header_t hdr = NULL;
33 envelope_t env; 33 envelope_t env;
34 attribute_t attr; 34 attribute_t attr;
35 char *from, *subj; 35 char *from = NULL, *subj = NULL;
36 int froml, subjl; 36 int froml, subjl;
37 char date[80], st[10]; 37 char date[80], st[10];
38 int cols = util_getcols () - 6; 38 int cols = util_getcols () - 6;
...@@ -48,13 +48,27 @@ mail_from (int argc, char **argv) ...@@ -48,13 +48,27 @@ mail_from (int argc, char **argv)
48 if (util_isdeleted (cursor)) 48 if (util_isdeleted (cursor))
49 return 1; 49 return 1;
50 50
51 froml = cols / 3; 51 message_get_header (msg, &hdr);
52 subjl = cols * 2 / 3; 52 if (header_aget_value (hdr, MU_HEADER_FROM, &from) == 0)
53 if (froml + subjl > cols) 53 {
54 subjl--; 54 address_t address = NULL;
55 55 if (address_create (&address, from) == 0)
56 from = malloc (froml * sizeof (char)); 56 {
57 subj = malloc (subjl * sizeof (char)); 57 char p[128];
58 size_t len = strlen (from);
59 *p = '\0';
60 address_get_personal (address, 1, p, sizeof p, NULL);
61 if (*p && len)
62 {
63 strncpy (from, p, len - 1);
64 from[len - 1] = '\0';
65 }
66 else
67 address_get_email (address, 1, from, strlen (from), NULL);
68 address_destroy (&address);
69 }
70 }
71 header_aget_value (hdr, MU_HEADER_SUBJECT, &subj);
58 72
59 if (from == NULL || subj == NULL) 73 if (from == NULL || subj == NULL)
60 { 74 {
...@@ -63,10 +77,6 @@ mail_from (int argc, char **argv) ...@@ -63,10 +77,6 @@ mail_from (int argc, char **argv)
63 return 1; 77 return 1;
64 } 78 }
65 79
66 message_get_header (msg, &hdr);
67 header_get_value (hdr, MU_HEADER_FROM, from, froml, NULL);
68 header_get_value (hdr, MU_HEADER_SUBJECT, subj, subjl, NULL);
69
70 message_get_attribute (msg, &attr); 80 message_get_attribute (msg, &attr);
71 attribute_get_flags (attr, &flags); 81 attribute_get_flags (attr, &flags);
72 82
...@@ -91,9 +101,18 @@ mail_from (int argc, char **argv) ...@@ -91,9 +101,18 @@ mail_from (int argc, char **argv)
91 message_lines (msg, &m_lines); 101 message_lines (msg, &m_lines);
92 102
93 snprintf (st, sizeof(st), "%3ld/%-5ld", m_lines, m_size); 103 snprintf (st, sizeof(st), "%3ld/%-5ld", m_lines, m_size);
94 fprintf (ofile, "%c%c%4d %-18.18s %-16.16s %s %12.12s\n", 104
105 /* The "From" field will take a third of the screen.
106 Subject will take the rest.
107 FIXME: This is not quiet correct we use fix sizes
108 18, 16 for the other fields.
109 */
110 froml = cols / 3;
111 subjl = cols - froml - strlen (st) - strlen (date);
112
113 fprintf (ofile, "%c%c%4d %-18.18s %-16.16s %s %.*s\n",
95 cursor == realcursor ? '>' : ' ', cflag, cursor, 114 cursor == realcursor ? '>' : ' ', cflag, cursor,
96 from, date, st, subj); 115 from, date, st, (subjl < 0) ? 0 : subjl, subj);
97 116
98 free (from); 117 free (from);
99 free (subj); 118 free (subj);
......