Commit 4e28d683 4e28d683d6ea3a57e4acf907164196cc44c6a5c3 by Sam Roberts

Don't mkdir unless the mailbox can be opened, and better cleanup on error

detection.
1 parent a013b372
...@@ -32,16 +32,12 @@ main (int argc, char **argv) ...@@ -32,16 +32,12 @@ main (int argc, char **argv)
32 mbox_name = argv[1]; 32 mbox_name = argv[1];
33 dir_name = argv[2]; 33 dir_name = argv[2];
34 34
35 if (mkdir (dir_name, 0777) != 0)
36 {
37 fprintf (stderr, "mkdir(%s) failed: %s\n", dir_name, strerror (errno));
38 exit (1);
39 }
40 /* Register the desire formats. */ 35 /* Register the desire formats. */
41 { 36 {
42 list_t bookie; 37 list_t bookie;
43 registrar_get_list (&bookie); 38 registrar_get_list (&bookie);
44 list_append (bookie, path_record); 39 list_append (bookie, path_record);
40 list_append (bookie, imap_record);
45 } 41 }
46 42
47 if ((status = mailbox_create_default (&mbox, mbox_name)) != 0) 43 if ((status = mailbox_create_default (&mbox, mbox_name)) != 0)
...@@ -64,6 +60,13 @@ main (int argc, char **argv) ...@@ -64,6 +60,13 @@ main (int argc, char **argv)
64 } 60 }
65 mailbox_messages_count (mbox, &count); 61 mailbox_messages_count (mbox, &count);
66 62
63 if (mkdir (dir_name, 0777) != 0)
64 {
65 fprintf (stderr, "mkdir(%s) failed: %s\n", dir_name, strerror (errno));
66 mailbox_close (mbox);
67 exit (1);
68 }
69
67 for (msgno = 1; msgno <= count; ++msgno) 70 for (msgno = 1; msgno <= count; ++msgno)
68 { 71 {
69 message_t msg = 0; 72 message_t msg = 0;
...@@ -74,12 +77,14 @@ main (int argc, char **argv) ...@@ -74,12 +77,14 @@ main (int argc, char **argv)
74 { 77 {
75 fprintf (stderr, "msg %d: get message failed: %s\n", 78 fprintf (stderr, "msg %d: get message failed: %s\n",
76 msgno, strerror (status)); 79 msgno, strerror (status));
77 exit (2); 80 mailbox_close (mbox);
81 exit (1);
78 } 82 }
79 if ((status = message_get_num_parts (msg, &nparts))) 83 if ((status = message_get_num_parts (msg, &nparts)))
80 { 84 {
81 fprintf (stderr, "msg %d: get num parts failed: %s\n", 85 fprintf (stderr, "msg %d: get num parts failed: %s\n",
82 msgno, strerror (status)); 86 msgno, strerror (status));
87 mailbox_close (mbox);
83 exit (1); 88 exit (1);
84 } 89 }
85 printf ("msg %03d: %02d parts\n", msgno, nparts); 90 printf ("msg %03d: %02d parts\n", msgno, nparts);
...@@ -97,6 +102,7 @@ main (int argc, char **argv) ...@@ -97,6 +102,7 @@ main (int argc, char **argv)
97 { 102 {
98 fprintf (stderr, "msg %d: get part %d failed: %s\n", 103 fprintf (stderr, "msg %d: get part %d failed: %s\n",
99 msgno, partno, strerror (status)); 104 msgno, partno, strerror (status));
105 mailbox_close (mbox);
100 exit (1); 106 exit (1);
101 } 107 }
102 if ((status = message_save_attachment (part, path, 0))) 108 if ((status = message_save_attachment (part, path, 0)))
......