summaryrefslogtreecommitdiff
path: root/src/mail/move.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/mail/move.cc')
-rw-r--r--src/mail/move.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/mail/move.cc b/src/mail/move.cc
new file mode 100644
index 0000000..bbcce0d
--- /dev/null
+++ b/src/mail/move.cc
@@ -0,0 +1,60 @@
1/*************************************************************************
2 *
3 * HTCd - Copyright (C) 1998-2006 Henrik Rydberg
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <mail/res.h>
21#include <mt/lock.h>
22
23static fp_stream mout(stdout),merr(stderr);
24
25main(int argc,char* argv[])
26{
27 if(argc<3) {
28 merr<<"Usage: "<<argv[0]<<" <frombox> <tobox> [indices]\n";
29 return -1;
30 }
31 const char* infile=argv[1];
32 const char* outfile=argv[2];
33 Mailbox box,keep;
34 LockFile(infile);
35 LockFile(outfile);
36 FILE* outbox=fopen(outfile,"a+");
37 if(outbox) {
38 GetMessages(box,infile);
39 for(int i=0;i<box.size();i++) {
40 int move=0;
41 if(argc>3) {
42 for(int j=3;j<argc;j++) if(atoi(argv[j])-1==i) { move=1; break; }
43 }
44 else {
45 move=1;
46 }
47 if(move) AppendMessage(outbox,box[i]);
48 else keep.push_back(box[i]);
49 }
50 if(fclose(outbox)) {
51 merr<<"Write error: messages kept (but possibly duplicates).\n";
52 }
53 else {
54 PutMessages(keep,infile);
55 }
56 }
57 UnlockFile(outfile);
58 UnlockFile(infile);
59 return 0;
60}