New globals: current_folder, current_message, mh_list_format, etc.
Showing
1 changed file
with
117 additions
and
0 deletions
... | @@ -19,11 +19,28 @@ | ... | @@ -19,11 +19,28 @@ |
19 | 19 | ||
20 | #include <mh.h> | 20 | #include <mh.h> |
21 | #include <pwd.h> | 21 | #include <pwd.h> |
22 | #include <sys/types.h> | ||
23 | #include <sys/stat.h> | ||
24 | |||
25 | char *current_folder = "inbox"; | ||
26 | size_t current_message; | ||
27 | char mh_list_format[] = | ||
28 | "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>" | ||
29 | "%02(mon{date})/%02(mday{date})" | ||
30 | "%<{date} %|*%>" | ||
31 | "%<(mymbox{from})%<{to}To:%14(friendly{to})%>%>" | ||
32 | "%<(zero)%17(friendly{from})%>" | ||
33 | " %{subject}%<{body}<<%{body}>>%>"; | ||
34 | |||
22 | 35 | ||
23 | void | 36 | void |
24 | mh_init () | 37 | mh_init () |
25 | { | 38 | { |
26 | list_t bookie; | 39 | list_t bookie; |
40 | char *ctx_name; | ||
41 | header_t header = NULL; | ||
42 | |||
43 | /* Register mailbox formats */ | ||
27 | registrar_get_list (&bookie); | 44 | registrar_get_list (&bookie); |
28 | list_append (bookie, mh_record); | 45 | list_append (bookie, mh_record); |
29 | list_append (bookie, mbox_record); | 46 | list_append (bookie, mbox_record); |
... | @@ -33,8 +50,108 @@ mh_init () | ... | @@ -33,8 +50,108 @@ mh_init () |
33 | /* Possible supported mailers. */ | 50 | /* Possible supported mailers. */ |
34 | list_append (bookie, sendmail_record); | 51 | list_append (bookie, sendmail_record); |
35 | list_append (bookie, smtp_record); | 52 | list_append (bookie, smtp_record); |
53 | |||
54 | /* Set MH context */ | ||
55 | current_folder = mu_tilde_expansion (current_folder, "/", NULL); | ||
56 | if (strchr (current_folder, '/') == NULL) | ||
57 | { | ||
58 | char *p = mu_get_homedir (); | ||
59 | asprintf (¤t_folder, "mh:%s/Mail/%s", p, current_folder); | ||
60 | if (!current_folder) | ||
61 | { | ||
62 | mh_error ("low memory"); | ||
63 | exit (1); | ||
64 | } | ||
65 | } | ||
66 | else if (strchr (current_folder, ':') == NULL) | ||
67 | { | ||
68 | char *p; | ||
69 | p = xmalloc (strlen (current_folder) + 4); | ||
70 | strcat (strcpy (p, "mh:"), current_folder); | ||
71 | current_folder = p; | ||
72 | } | ||
73 | |||
74 | ctx_name = xmalloc (strlen (current_folder)+sizeof (MH_SEQUENCES_FILE)+2); | ||
75 | sprintf (ctx_name, "%s/%s", current_folder+3, MH_SEQUENCES_FILE); | ||
76 | if (mh_read_context_file (ctx_name, &header) == 0) | ||
77 | { | ||
78 | char buf[64]; | ||
79 | size_t n; | ||
80 | |||
81 | if (!header_get_value (header, "cur", buf, sizeof buf, &n)) | ||
82 | current_message = strtoul (buf, NULL, 10); | ||
83 | header_destroy (&header, NULL); | ||
84 | } | ||
85 | free (ctx_name); | ||
36 | } | 86 | } |
37 | 87 | ||
88 | int | ||
89 | mh_read_context_file (char *path, header_t *header) | ||
90 | { | ||
91 | int status; | ||
92 | char *blurb; | ||
93 | struct stat st; | ||
94 | FILE *fp; | ||
95 | |||
96 | if (stat (path, &st)) | ||
97 | return errno; | ||
98 | |||
99 | blurb = malloc (st.st_size); | ||
100 | if (!blurb) | ||
101 | return ENOMEM; | ||
102 | |||
103 | fp = fopen (path, "r"); | ||
104 | if (!fp) | ||
105 | { | ||
106 | free (blurb); | ||
107 | return errno; | ||
108 | } | ||
109 | |||
110 | fread (blurb, st.st_size, 1, fp); | ||
111 | fclose (fp); | ||
112 | |||
113 | if (status = header_create (header, blurb, st.st_size, NULL)) | ||
114 | free (blurb); | ||
115 | |||
116 | return status; | ||
117 | } | ||
118 | |||
119 | char * | ||
120 | mh_read_formfile (char *name) | ||
121 | { | ||
122 | FILE *fp; | ||
123 | struct stat st; | ||
124 | char *ptr; | ||
125 | size_t off = 0; | ||
126 | char *format_str; | ||
127 | |||
128 | if (stat (name, &st)) | ||
129 | { | ||
130 | mh_error ("can't stat format file %s: %s", name, strerror (errno)); | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | fp = fopen (name, "r"); | ||
135 | if (!fp) | ||
136 | { | ||
137 | mh_error ("can't open format file %s: %s", name, strerror (errno)); | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | format_str = xmalloc (st.st_size+1); | ||
142 | while ((ptr = fgets (format_str + off, st.st_size - off, fp)) != NULL) | ||
143 | { | ||
144 | int len = strlen (ptr); | ||
145 | if (len == 0) | ||
146 | break; | ||
147 | if (len > 0 && ptr[len-1] == '\n') | ||
148 | ptr[--len] = 0; | ||
149 | off += len; | ||
150 | } | ||
151 | format_str[off] = 0; | ||
152 | fclose (fp); | ||
153 | return format_str; | ||
154 | } | ||
38 | 155 | ||
39 | static char *my_name; | 156 | static char *my_name; |
40 | static char *my_email; | 157 | static char *my_email; | ... | ... |
-
Please register or sign in to post a comment