Read user's profile. Use values from there instead of hardcoded ones.
Showing
1 changed file
with
54 additions
and
14 deletions
... | @@ -22,10 +22,12 @@ | ... | @@ -22,10 +22,12 @@ |
22 | #include <sys/types.h> | 22 | #include <sys/types.h> |
23 | #include <sys/stat.h> | 23 | #include <sys/stat.h> |
24 | 24 | ||
25 | char *current_folder = "inbox"; | 25 | char *current_folder = NULL; |
26 | size_t current_message; | 26 | size_t current_message; |
27 | char *ctx_name; | 27 | char *ctx_name; |
28 | header_t ctx_header; | 28 | header_t ctx_header; |
29 | header_t profile_header; | ||
30 | |||
29 | char mh_list_format[] = | 31 | char mh_list_format[] = |
30 | "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>" | 32 | "%4(msg)%<(cur)+%| %>%<{replied}-%?{encrypted}E%| %>" |
31 | "%02(mon{date})/%02(mday{date})" | 33 | "%02(mon{date})/%02(mday{date})" |
... | @@ -39,6 +41,7 @@ void | ... | @@ -39,6 +41,7 @@ void |
39 | mh_init () | 41 | mh_init () |
40 | { | 42 | { |
41 | list_t bookie; | 43 | list_t bookie; |
44 | char *mh_sequences_name; | ||
42 | 45 | ||
43 | /* Register mailbox formats */ | 46 | /* Register mailbox formats */ |
44 | registrar_get_list (&bookie); | 47 | registrar_get_list (&bookie); |
... | @@ -51,12 +54,24 @@ mh_init () | ... | @@ -51,12 +54,24 @@ mh_init () |
51 | list_append (bookie, sendmail_record); | 54 | list_append (bookie, sendmail_record); |
52 | list_append (bookie, smtp_record); | 55 | list_append (bookie, smtp_record); |
53 | 56 | ||
57 | /* Read user's profile */ | ||
58 | mh_read_profile (); | ||
59 | |||
54 | /* Set MH context */ | 60 | /* Set MH context */ |
55 | current_folder = mu_tilde_expansion (current_folder, "/", NULL); | 61 | if (current_folder) |
62 | current_folder = mu_tilde_expansion (current_folder, "/", NULL); | ||
63 | else | ||
64 | current_folder = mh_profile_value ("Current-Folder", | ||
65 | mh_profile_value ("Inbox", "inbox")); | ||
56 | if (strchr (current_folder, '/') == NULL) | 66 | if (strchr (current_folder, '/') == NULL) |
57 | { | 67 | { |
68 | char *mhdir = mh_profile_value ("Path", "Mail"); | ||
58 | char *p = mu_get_homedir (); | 69 | char *p = mu_get_homedir (); |
59 | asprintf (¤t_folder, "mh:%s/Mail/%s", p, current_folder); | 70 | |
71 | if (mhdir[0] == '/') | ||
72 | asprintf (¤t_folder, "mh:%s/%s", mhdir, current_folder); | ||
73 | else | ||
74 | asprintf (¤t_folder, "mh:%s/%s/%s", p, mhdir, current_folder); | ||
60 | if (!current_folder) | 75 | if (!current_folder) |
61 | { | 76 | { |
62 | mh_error ("low memory"); | 77 | mh_error ("low memory"); |
... | @@ -71,18 +86,45 @@ mh_init () | ... | @@ -71,18 +86,45 @@ mh_init () |
71 | current_folder = p; | 86 | current_folder = p; |
72 | } | 87 | } |
73 | 88 | ||
74 | ctx_name = xmalloc (strlen (current_folder)+sizeof (MH_SEQUENCES_FILE)+2); | 89 | mh_sequences_name = mh_profile_value ("mh-sequences", MH_SEQUENCES_FILE); |
75 | sprintf (ctx_name, "%s/%s", current_folder+3, MH_SEQUENCES_FILE); | 90 | asprintf (&ctx_name, "%s/%s", current_folder+3, mh_sequences_name); |
76 | if (mh_read_context_file (ctx_name, &ctx_header) == 0) | 91 | if (mh_read_context_file (ctx_name, &ctx_header) == 0) |
77 | { | 92 | { |
78 | char buf[64]; | 93 | char buf[64]; |
79 | size_t n; | 94 | size_t n; |
80 | 95 | ||
81 | if (!header_get_value (ctx_header, "cur", buf, sizeof buf, &n)) | 96 | if (!header_get_value (ctx_header, "cur", buf, sizeof buf, &n)) |
82 | current_message = strtoul (buf, NULL, 10); | 97 | current_message = strtoul (buf, NULL, 10); |
83 | } | 98 | } |
84 | } | 99 | } |
85 | 100 | ||
101 | char * | ||
102 | mh_profile_value (char *name, char *defval) | ||
103 | { | ||
104 | char *p; | ||
105 | if (header_aget_value (profile_header, name, &p)) | ||
106 | p = defval; | ||
107 | return p; | ||
108 | } | ||
109 | |||
110 | void | ||
111 | mh_read_profile () | ||
112 | { | ||
113 | char *p; | ||
114 | |||
115 | p = getenv ("MH"); | ||
116 | if (p) | ||
117 | p = mu_tilde_expansion (p, "/", NULL); | ||
118 | else | ||
119 | { | ||
120 | char *home = mu_get_homedir (); | ||
121 | if (!home) | ||
122 | abort (); /* shouldn't happen */ | ||
123 | asprintf (&p, "%s/%s", home, MH_USER_PROFILE); | ||
124 | } | ||
125 | mh_read_context_file (p, &profile_header); | ||
126 | } | ||
127 | |||
86 | void | 128 | void |
87 | mh_save_context () | 129 | mh_save_context () |
88 | { | 130 | { |
... | @@ -213,12 +255,9 @@ mh_read_formfile (char *name, char **pformat) | ... | @@ -213,12 +255,9 @@ mh_read_formfile (char *name, char **pformat) |
213 | static char *my_name; | 255 | static char *my_name; |
214 | static char *my_email; | 256 | static char *my_email; |
215 | 257 | ||
216 | /* FIXME: this lacks domain name part! */ | ||
217 | void | 258 | void |
218 | mh_get_my_name (char *name) | 259 | mh_get_my_name (char *name) |
219 | { | 260 | { |
220 | char hostname[256]; | ||
221 | |||
222 | if (!name) | 261 | if (!name) |
223 | { | 262 | { |
224 | struct passwd *pw = getpwuid (getuid ()); | 263 | struct passwd *pw = getpwuid (getuid ()); |
... | @@ -231,10 +270,7 @@ mh_get_my_name (char *name) | ... | @@ -231,10 +270,7 @@ mh_get_my_name (char *name) |
231 | } | 270 | } |
232 | 271 | ||
233 | my_name = strdup (name); | 272 | my_name = strdup (name); |
234 | gethostname(hostname, sizeof(hostname)); | 273 | my_email = mu_get_user_email (name); |
235 | hostname[sizeof(hostname)-1] = 0; | ||
236 | my_email = xmalloc (strlen (name) + strlen (hostname) + 2); | ||
237 | sprintf (my_email, "%s@%s", name, hostname); | ||
238 | } | 274 | } |
239 | 275 | ||
240 | 276 | ||
... | @@ -263,7 +299,11 @@ mh_check_folder (char *pathname) | ... | @@ -263,7 +299,11 @@ mh_check_folder (char *pathname) |
263 | { | 299 | { |
264 | if (mh_getyn ("Create folder \"%s\"", p)) | 300 | if (mh_getyn ("Create folder \"%s\"", p)) |
265 | { | 301 | { |
266 | if (mkdir (p, 0777)) /* FIXME: Permissions */ | 302 | int perm = 0711; |
303 | char *pb = mh_profile_value ("Folder-Protect", NULL); | ||
304 | if (pb) | ||
305 | perm = strtoul (pb, NULL, 8); | ||
306 | if (mkdir (p, perm)) | ||
267 | { | 307 | { |
268 | mh_error ("Can't create directory %s: %s", | 308 | mh_error ("Can't create directory %s: %s", |
269 | p, strerror (errno)); | 309 | p, strerror (errno)); | ... | ... |
-
Please register or sign in to post a comment