1 #ifndef cmlm_h
2 #define cmlm_h
3 /*
4 ** Copyright 2000-2007 Double Precision, Inc.
5 ** See COPYING for distribution information.
6 */
7
8 static const char cmlm_h_rcsid[]="$Id: cmlm.h,v 1.13 2007/03/11 04:44:43 mrsam Exp $";
9
10 #include "config.h"
11 #include "afx/afx.h"
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16
17 #include <iostream>
18
19 #include <string>
20 #include <vector>
21 #include <algorithm>
22 #include <functional>
23 #include <cctype>
24
25 #define TMP "tmp"
26 #define TMPLOCK "tmp.lock"
27
28 #define OPTIONS "options"
29 #define DOMAINS "sublist"
30 #define ARCHIVE "archive"
31 #define UNSUBLIST "unsublist"
32 #define COMMANDS "commands"
33 #define COMMANDSDAT "commands.dat"
34
35 #define BOUNCES "bounces"
36 #define BOUNCESDAT "bounces.dat"
37 #define BOUNCESLOCK "bounces.lock"
38
39
40 #define HOURLYLOCKFILE "hourly.lock"
41 #define DAILYLOCKFILE "daily.lock"
42
43 #define DIGESTLOCKFILE "digest.lock"
44
45 #define MODQUEUE "modqueue"
46 #define MODQUEUELOCKFILE "modqueue.lock"
47
48 #define HEADERADD "headeradd"
49 #define HEADERDEL "headerdel"
50
51 #include "datadir.h"
52
53 #define TEMPLATEDIR DATADIR "/couriermlm"
54
55 #define MSGSEPARATOR "===="
56
57 #include "bindir.h"
58
59 #define SENDMAIL "/usr/sbin/sendmail"
60 #define REFORMIME BINDIR "/reformime"
61 #define MAXRCPTS 20
62
63 #define MSGLOCKFILE ARCHIVE "/.lock"
64 #define SEQNO ARCHIVE "/.seqno"
65 #define NEXTSEQNO ARCHIVE "/.nextseqno"
66
67 //
68 // Large domains have their own db file listing the subscribers.
69 // Small domains are all lumped into one file, keyed by domain name,
70 // data is address\0subinfo\0address\0subinfo...
71 //
72
73 #define MISC DOMAINS "/misc"
74 #define MISCSIZE 2
75
76 #define ALIASES DOMAINS "/aliases"
77
78 #define SUBLOCKFILE "sublist.lock"
79 #define CMDLOCKFILE "commands.lock"
80
81 #define SUBLOGFILE "sublist.log"
82
83 class ExclusiveLock {
84 int fd;
85 public:
86 ExclusiveLock(const char *);
87 ~ExclusiveLock();
88 } ;
89
90 class SharedLock {
91 int fd;
92 public:
93 SharedLock(const char *);
94 ~SharedLock();
95 } ;
96
97 class SubSharedLock : public SharedLock {
98 public:
99 SubSharedLock();
100 ~SubSharedLock();
101 } ;
102
103 class SubExclusiveLock : public ExclusiveLock {
104 public:
105 SubExclusiveLock();
106 ~SubExclusiveLock();
107 } ;
108
109 class CommandLock : public ExclusiveLock {
110 public:
111 CommandLock();
112 ~CommandLock();
113 } ;
114
115 void trapsigs(const char *);
116 void clearsigs(int);
117
118 std::string cmdget_s(const char *);
119
120 template<typename iterator_t, typename comp_t>
find_last_if(iterator_t b,iterator_t e,comp_t c)121 iterator_t find_last_if(iterator_t b, iterator_t e,
122 comp_t c)
123 {
124 iterator_t r=e;
125
126 while (b != e)
127 if (c(*b++))
128 r=b;
129 return r;
130 }
131
132
TrimLeft(std::string & s)133 inline void TrimLeft(std::string &s)
134 {
135 s=std::string(std::find_if(s.begin(), s.end(),
136 std::not1(std::ptr_fun(::isspace))), s.end());
137 }
138
TrimRight(std::string & s)139 inline void TrimRight(std::string &s)
140 {
141 s=std::string(s.begin(), find_last_if(s.begin(), s.end(),
142 std::not1(std::ptr_fun(::isspace)))
143 );
144 }
145
146 std::string get_verp_return(std::string addr);
147
148 std::string toverp(std::string);
149
150 std::string fromverp(std::string);
151
152 std::string readmsg();
153
154 std::string header_s(std::string a, const char *b);
155
156 std::string returnaddr(std::string, const char *);
157
158 std::string mkboundary_msg_s(afxipipestream &);
159
160 std::string mkfilename();
161 std::string mktmpfilename();
162 void post(std::istream &, const char *);
163
164 int is_subscriber(std::string);
165 int getinfo(std::string, int (*)(std::string));
166 std::string myname();
167
168 void addrlower(char *);
169 void addrlower(std::string &); // TODO
170
171 int isfound(std::string);
172 int sendmail(const char **, pid_t &);
173 int wait4sendmail(pid_t);
174 int sendmail_bcc(pid_t &, std::string, int nodsn = 0);
175
176 bool checkconfirm(std::string);
177
178 void ack_template(std::ostream &, const char *, std::string, std::string);
179 void simple_template(std::ostream &, const char *, std::string);
180 void copy_template(std::ostream &, const char *, std::string);
181 void copy_report(const char *, afxopipestream &);
182 int copyio(afxipipestream &, afxopipestream &);
183 int copyio_noseek(afxipipestream &, afxopipestream &);
184 int copyio_noseek_cnt(afxipipestream &, afxopipestream &, unsigned long *);
185 int cmddigest(const std::vector<std::string> &);
186
187 #endif
188