Commit 011e2cd7 011e2cd7785995c17f63878dc581f33743c5ff33 by Sergey Poznyakoff

moved mail_mbox_commit from mbox.c. Honour keepsave variable.

1 parent e511ac68
...@@ -50,3 +50,58 @@ mail_mbox_close () ...@@ -50,3 +50,58 @@ mail_mbox_close ()
50 return 0; 50 return 0;
51 } 51 }
52 52
53 int
54 mail_mbox_commit ()
55 {
56 int i;
57 mailbox_t dest_mbox = NULL;
58 int saved_count = 0;
59 message_t msg;
60 attribute_t attr;
61 int keepsave = util_find_env("keepsave")->set;
62
63 for (i = 1; i <= total; i++)
64 {
65 if (mailbox_get_message (mbox, i, &msg))
66 {
67 fprintf (ofile, "%d: can't get message\n", i);
68 return 1;
69 }
70 message_get_attribute (msg, &attr);
71 if (attribute_is_userflag (attr, MAIL_ATTRIBUTE_MBOXED))
72 {
73 if (!dest_mbox)
74 {
75 char *name = getenv ("MBOX");
76
77 if (mailbox_create_default (&dest_mbox, name)
78 || mailbox_open (dest_mbox,
79 MU_STREAM_WRITE | MU_STREAM_CREAT))
80 {
81 fprintf (ofile, "can't create mailbox %s\n", name);
82 return 1;
83 }
84 }
85
86 mailbox_append_message (dest_mbox, msg);
87 attribute_set_deleted (attr);
88 saved_count++;
89 }
90 else if (!keepsave && attribute_is_userflag (attr, MAIL_ATTRIBUTE_SAVED))
91 {
92 attribute_set_deleted (attr);
93 }
94 }
95
96 if (saved_count)
97 {
98 url_t url = NULL;
99
100 mailbox_get_url (dest_mbox, &url);
101 fprintf(ofile, "Saved %d messages in %s\n", saved_count,
102 url_to_string (url));
103 mailbox_close (dest_mbox);
104 mailbox_destroy (&dest_mbox);
105 }
106 return 0;
107 }
......