Commit e511ac68 e511ac6823cfb329c16b6a9b6eebdee0124547e3 by Sergey Poznyakoff

move mail_mbox_commit to quit.c

1 parent 2ed8d7b9
...@@ -28,7 +28,7 @@ mail_mbox (int argc, char **argv) ...@@ -28,7 +28,7 @@ mail_mbox (int argc, char **argv)
28 attribute_t attr; 28 attribute_t attr;
29 29
30 if (argc > 1) 30 if (argc > 1)
31 return util_msglist_command (mail_mbox, argc, argv); 31 return util_msglist_command (mail_mbox, argc, argv, 1);
32 else 32 else
33 { 33 {
34 if (mailbox_get_message (mbox, cursor, &msg)) 34 if (mailbox_get_message (mbox, cursor, &msg))
...@@ -43,54 +43,4 @@ mail_mbox (int argc, char **argv) ...@@ -43,54 +43,4 @@ mail_mbox (int argc, char **argv)
43 return 0; 43 return 0;
44 } 44 }
45 45
46 int
47 mail_mbox_commit ()
48 {
49 int i;
50 mailbox_t dest_mbox = NULL;
51 int saved_count = 0;
52 message_t msg;
53 attribute_t attr;
54
55 for (i = 1; i <= total; i++)
56 {
57 if (mailbox_get_message (mbox, i, &msg))
58 {
59 fprintf (ofile, "%d: can't get message\n", i);
60 return 1;
61 }
62 message_get_attribute (msg, &attr);
63 if (attribute_is_userflag (attr, MAIL_ATTRIBUTE_MBOXED))
64 {
65 if (!dest_mbox)
66 {
67 char *name = getenv ("MBOX");
68
69 if (mailbox_create_default (&dest_mbox, name)
70 || mailbox_open (dest_mbox,
71 MU_STREAM_WRITE | MU_STREAM_CREAT))
72 {
73 fprintf (ofile, "can't create mailbox %s\n", name);
74 return 1;
75 }
76 }
77
78 mailbox_append_message (dest_mbox, msg);
79 attribute_set_deleted (attr);
80 saved_count++;
81 }
82 }
83
84 if (saved_count)
85 {
86 url_t url = NULL;
87
88 mailbox_get_url (dest_mbox, &url);
89 fprintf(ofile, "Saved %d messages in %s\n", saved_count,
90 url_to_string (url));
91 mailbox_close (dest_mbox);
92 mailbox_destroy (&dest_mbox);
93 }
94 return 0;
95 }
96 46
......