comparison src/sm-archive.cpp @ 21:09564d4acd9e stable-1-0-8

patches from Marco d'Itri for postfix
author Carl Byington <carl@five-ten-sg.com>
date Fri, 24 Dec 2010 15:13:18 -0800
parents b24369330483
children 9298f8b00db2
comparison
equal deleted inserted replaced
20:a7564d29fd53 21:09564d4acd9e
106 // syslog a message 106 // syslog a message
107 // 107 //
108 void my_syslog(mlfiPriv *priv, const char *text) { 108 void my_syslog(mlfiPriv *priv, const char *text) {
109 char buf[maxlen]; 109 char buf[maxlen];
110 if (priv) { 110 if (priv) {
111 snprintf(buf, sizeof(buf), "%s: %s", priv->queueid, text); 111 snprintf(buf, sizeof(buf), "%s: %s",
112 priv->queueid ? priv->queueid : "NOQUEUE", text);
112 text = buf; 113 text = buf;
113 } 114 }
114 if (use_syslog) { 115 if (use_syslog) {
115 pthread_mutex_lock(&syslog_mutex); 116 pthread_mutex_lock(&syslog_mutex);
116 if (!syslog_opened) { 117 if (!syslog_opened) {
133 //////////////////////////////////////////////// 134 ////////////////////////////////////////////////
134 // this email address is passed in from sendmail, and will 135 // this email address is passed in from sendmail, and will
135 // always be enclosed in <>. It may have mixed case, just 136 // always be enclosed in <>. It may have mixed case, just
136 // as the mail client sent it. We dup the string and convert 137 // as the mail client sent it. We dup the string and convert
137 // the duplicate to lower case. 138 // the duplicate to lower case.
139 // Postfix will return addresses without <> if they have been provided
140 // this way in the SMTP dialog.
138 // 141 //
139 const char *to_lower_string(const char *email); 142 const char *to_lower_string(const char *email);
140 const char *to_lower_string(const char *email) { 143 const char *to_lower_string(const char *email) {
141 int n = strlen(email)-2; 144 char *key, *p;
142 if (n < 1) return strdup(email); 145 int i;
143 char *key = strdup(email+1); 146
144 key[n] = '\0'; 147 if (strcmp(email, "<>") == 0) return strdup(email);
145 for (int i=0; i<n; i++) key[i] = tolower(key[i]); 148 if (email[0] == '<') p = (char *) email + 1;
149 else p = (char *) email;
150 key = (char *) malloc(strlen(p) + 1);
151 for (i = 0; p[i] != '\0'; i++) key[i] = tolower(p[i]);
152 if (p[i - 1] == '>') i--;
153 key[i] = '\0';
146 return key; 154 return key;
147 } 155 }
148 156
149 157
150 //////////////////////////////////////////////// 158 ////////////////////////////////////////////////
187 195
188 sfsistat mlfi_envrcpt(SMFICTX *ctx, char **rcpt) 196 sfsistat mlfi_envrcpt(SMFICTX *ctx, char **rcpt)
189 { 197 {
190 mlfiPriv &priv = *MLFIPRIV; 198 mlfiPriv &priv = *MLFIPRIV;
191 CONFIG &dc = *priv.pc; 199 CONFIG &dc = *priv.pc;
192 if (!priv.queueid) priv.queueid = strdup(smfi_getsymval(ctx, (char*)"i")); 200 const char *i_macro = smfi_getsymval(ctx, (char*)"i");
201 if (!priv.queueid && i_macro) priv.queueid = strdup(i_macro);
193 const char *rcptaddr = to_lower_string(rcpt[0]); 202 const char *rcptaddr = to_lower_string(rcpt[0]);
194 if (debug_syslog > 1) { 203 if (debug_syslog > 1) {
195 char msg[maxlen]; 204 char msg[maxlen];
196 snprintf(msg, sizeof(msg), "from <%s> to <%s>", priv.mailaddr, rcptaddr); 205 snprintf(msg, sizeof(msg), "from <%s> to <%s>", priv.mailaddr, rcptaddr);
197 my_syslog(&priv, msg); 206 my_syslog(&priv, msg);
206 215
207 sfsistat mlfi_eom(SMFICTX *ctx) 216 sfsistat mlfi_eom(SMFICTX *ctx)
208 { 217 {
209 mlfiPriv &priv = *MLFIPRIV; 218 mlfiPriv &priv = *MLFIPRIV;
210 CONFIG &dc = *priv.pc; 219 CONFIG &dc = *priv.pc;
220 const char *i_macro = smfi_getsymval(ctx, (char*)"i");
221 if (!priv.queueid && i_macro) priv.queueid = strdup(i_macro);
211 const char *target = dc.find_from(priv.mailaddr); 222 const char *target = dc.find_from(priv.mailaddr);
212 add_target(priv, target); 223 add_target(priv, target);
213 for (string_set::iterator i=priv.targets.begin(); i!=priv.targets.end(); i++) { 224 for (string_set::iterator i=priv.targets.begin(); i!=priv.targets.end(); i++) {
214 target = (*i); 225 target = (*i);
215 smfi_addrcpt(ctx, (char*)target); 226 smfi_addrcpt(ctx, (char*)target);