summaryrefslogtreecommitdiff
path: root/src/mail
diff options
context:
space:
mode:
Diffstat (limited to 'src/mail')
-rw-r--r--src/mail/inbox.cc36
-rw-r--r--src/mail/list.cc52
-rw-r--r--src/mail/move.cc60
-rw-r--r--src/mail/res.h30
4 files changed, 178 insertions, 0 deletions
diff --git a/src/mail/inbox.cc b/src/mail/inbox.cc
new file mode 100644
index 0000000..b605cd3
--- /dev/null
+++ b/src/mail/inbox.cc
@@ -0,0 +1,36 @@
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#include <unistd.h>
23
24main(int argc,char* argv[])
25{
26 if(argc<3) return -1;
27 const char* infile=INBOX.c_str(); // argv[1] not used
28 const char* outfile=argv[2];
29 LockFile(infile);
30 Mailbox box;
31 GetMessages(box,infile);
32 int ok=AppendMessages(box,outfile);
33 if(ok) truncate(infile,0);
34 UnlockFile(infile);
35 return !ok;
36}
diff --git a/src/mail/list.cc b/src/mail/list.cc
new file mode 100644
index 0000000..f50c41b
--- /dev/null
+++ b/src/mail/list.cc
@@ -0,0 +1,52 @@
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 <mime/enc.h>
22
23static fp_stream mout(stdout),merr(stderr);
24const mstring multipart="multipart/";
25
26main(int argc,char* argv[]) try
27{
28 if(argc<2) {
29 merr<<"Usage: "<<argv[0]<<" <inbox> [index]\n";
30 return -1;
31 }
32 const char* infile=argv[1];
33 Mailbox box;
34 GetMessages(box,infile);
35 if(argc>2) {
36 int m=atoi(argv[2])-1;
37 if(m>=0&&m<box.size()) mout<<box[m]<<"\n";
38 }
39 else {
40 merr<<"Read "<<box.size()<<" messages.\n";
41 for(int i=0;i<box.size();i++) {
42 Message msg(box[i]);
43 int multi=msg.cont_type.find(multipart)>=0;
44 mout<<"["<<(i+1)<<"]["<<multi<<"]["<<msg.subject<<"]["<<msg.from<<"]\n";
45 }
46 }
47 return 0;
48}
49catch(const merror_t& e)
50{
51 fprintf(stderr,"main: %d: %s\n",e.num,e.desc.c_str());
52}
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}
diff --git a/src/mail/res.h b/src/mail/res.h
new file mode 100644
index 0000000..5c54c31
--- /dev/null
+++ b/src/mail/res.h
@@ -0,0 +1,30 @@
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#ifndef MAILRESH
21#define MAILRESH
22
23#include <mime/mailbox.h>
24#include <mt/config.h>
25
26const mstring INBOX=htchome()+sref("/mail/INBOX");
27const mstring TODO=htchome()+sref("/mail/TODO");
28const mstring DONE=htchome()+sref("/mail/DONE");
29
30#endif