(mh_init2): Fixed generation of the sequence file
name. (mh_open_folder): Take an extra argument: a flag specifying whether the folder should be created. (mh_expand_name): Changed return data type.
Showing
1 changed file
with
16 additions
and
8 deletions
... | @@ -81,11 +81,13 @@ mh_init2 () | ... | @@ -81,11 +81,13 @@ mh_init2 () |
81 | "inbox")); | 81 | "inbox")); |
82 | 82 | ||
83 | mh_sequences_name = mh_profile_value ("mh-sequences", MH_SEQUENCES_FILE); | 83 | mh_sequences_name = mh_profile_value ("mh-sequences", MH_SEQUENCES_FILE); |
84 | asprintf (&seq_name, "%s/%s", current_folder+3, mh_sequences_name); | 84 | p = mh_expand_name (current_folder, 0); |
85 | asprintf (&seq_name, "%s/%s", p, mh_sequences_name); | ||
86 | free (p); | ||
85 | sequences = mh_context_create (seq_name, 1); | 87 | sequences = mh_context_create (seq_name, 1); |
86 | if (mh_context_read (sequences) == 0) | 88 | if (mh_context_read (sequences) == 0) |
87 | { | 89 | { |
88 | char *p = mh_context_get_value (sequences, "cur", "0"); | 90 | p = mh_context_get_value (sequences, "cur", "0"); |
89 | current_message = strtoul (p, NULL, 10); | 91 | current_message = strtoul (p, NULL, 10); |
90 | } | 92 | } |
91 | } | 93 | } |
... | @@ -196,7 +198,6 @@ mh_get_my_name (char *name) | ... | @@ -196,7 +198,6 @@ mh_get_my_name (char *name) |
196 | my_email = mu_get_user_email (name); | 198 | my_email = mu_get_user_email (name); |
197 | } | 199 | } |
198 | 200 | ||
199 | |||
200 | int | 201 | int |
201 | mh_is_my_name (char *name) | 202 | mh_is_my_name (char *name) |
202 | { | 203 | { |
... | @@ -215,7 +216,7 @@ mh_check_folder (char *pathname) | ... | @@ -215,7 +216,7 @@ mh_check_folder (char *pathname) |
215 | p++; | 216 | p++; |
216 | else | 217 | else |
217 | p = pathname; | 218 | p = pathname; |
218 | 219 | ||
219 | if (stat (p, &st)) | 220 | if (stat (p, &st)) |
220 | { | 221 | { |
221 | if (errno == ENOENT) | 222 | if (errno == ENOENT) |
... | @@ -346,12 +347,16 @@ mh_message_number (message_t msg, size_t *pnum) | ... | @@ -346,12 +347,16 @@ mh_message_number (message_t msg, size_t *pnum) |
346 | } | 347 | } |
347 | 348 | ||
348 | mailbox_t | 349 | mailbox_t |
349 | mh_open_folder (const char *folder) | 350 | mh_open_folder (const char *folder, int create) |
350 | { | 351 | { |
351 | mailbox_t mbox = NULL; | 352 | mailbox_t mbox = NULL; |
352 | char *name; | 353 | char *name; |
353 | 354 | int flags = MU_STREAM_READ; | |
355 | |||
354 | name = mh_expand_name (folder, 1); | 356 | name = mh_expand_name (folder, 1); |
357 | if (create && mh_check_folder (name)) | ||
358 | exit (0); | ||
359 | |||
355 | if (mailbox_create_default (&mbox, name)) | 360 | if (mailbox_create_default (&mbox, name)) |
356 | { | 361 | { |
357 | mh_error ("Can't create mailbox %s: %s", | 362 | mh_error ("Can't create mailbox %s: %s", |
... | @@ -359,7 +364,10 @@ mh_open_folder (const char *folder) | ... | @@ -359,7 +364,10 @@ mh_open_folder (const char *folder) |
359 | exit (1); | 364 | exit (1); |
360 | } | 365 | } |
361 | 366 | ||
362 | if (mailbox_open (mbox, MU_STREAM_READ)) | 367 | if (create) |
368 | flags |= MU_STREAM_CREAT; | ||
369 | |||
370 | if (mailbox_open (mbox, flags)) | ||
363 | { | 371 | { |
364 | mh_error ("Can't open mailbox %s: %s", name, strerror (errno)); | 372 | mh_error ("Can't open mailbox %s: %s", name, strerror (errno)); |
365 | exit (1); | 373 | exit (1); |
... | @@ -385,7 +393,7 @@ mh_get_dir () | ... | @@ -385,7 +393,7 @@ mh_get_dir () |
385 | return mhdir; | 393 | return mhdir; |
386 | } | 394 | } |
387 | 395 | ||
388 | const char * | 396 | char * |
389 | mh_expand_name (const char *name, int is_folder) | 397 | mh_expand_name (const char *name, int is_folder) |
390 | { | 398 | { |
391 | char *tmp = NULL; | 399 | char *tmp = NULL; | ... | ... |
-
Please register or sign in to post a comment