smtp_plain
};
-enum { /* Delivery modes */
- smtp_deliver_local,
- smtp_deliver_remote
-};
-
#define SMTP CC->SMTP
-#define SMTP_RECPS CC->SMTP_RECPS
-#define SMTP_ROOMS CC->SMTP_ROOMS
int run_queue_now = 0; /* Set to 1 to ignore SMTP send retry times */
/*
* Here's where our SMTP session begins its happy day.
*/
-void smtp_greeting(void)
+void smtp_greeting(int is_msa)
{
char message_to_spammer[1024];
CC->internal_pgm = 1;
CC->cs_flags |= CS_STEALTH;
SMTP = malloc(sizeof(struct citsmtp));
- SMTP_RECPS = malloc(SIZ);
- SMTP_ROOMS = malloc(SIZ);
memset(SMTP, 0, sizeof(struct citsmtp));
- memset(SMTP_RECPS, 0, SIZ);
- memset(SMTP_ROOMS, 0, SIZ);
+ SMTP->is_msa = is_msa;
/* If this config option is set, reject connections from problem
* addresses immediately instead of after they execute a RCPT
*/
- if (config.c_rbl_at_greeting) {
+ if ( (config.c_rbl_at_greeting) && (SMTP->is_msa == 0) ) {
if (rbl_check(message_to_spammer)) {
cprintf("550 %s\r\n", message_to_spammer);
CC->kill_me = 1;
- /* no need to free(valid), it's not allocated yet */
+ /* no need to free_recipients(valid), it's not allocated yet */
return;
}
}
config.c_maxsessions
);
CC->kill_me = 1;
- /* no need to free(valid), it's not allocated yet */
+ /* no need to free_recipients(valid), it's not allocated yet */
return;
}
#ifdef HAVE_OPENSSL
void smtps_greeting(void) {
CtdlStartTLS(NULL, NULL, NULL);
- smtp_greeting();
+ smtp_greeting(0);
}
#endif
* SMTP MSA port requires authentication.
*/
void smtp_msa_greeting(void) {
- smtp_greeting();
- SMTP->is_msa = 1;
+ smtp_greeting(1);
}
* LMTP is like SMTP but with some extra bonus footage added.
*/
void lmtp_greeting(void) {
- smtp_greeting();
+ smtp_greeting(0);
SMTP->is_lmtp = 1;
}
+/*
+ * Generic SMTP MTA greeting
+ */
+void smtp_mta_greeting(void) {
+ smtp_greeting(0);
+}
+
+
/*
* We also have an unfiltered LMTP socket that bypasses spam filters.
*/
void lmtp_unfiltered_greeting(void) {
- smtp_greeting();
+ smtp_greeting(0);
SMTP->is_lmtp = 1;
SMTP->is_unfiltered = 1;
}
if (config.c_rbl_at_greeting == 0) { /* Don't RBL again if we already did it */
if (rbl_check(message_to_spammer)) {
cprintf("550 %s\r\n", message_to_spammer);
- /* no need to free(valid), it's not allocated yet */
+ /* no need to free_recipients(valid), it's not allocated yet */
return;
}
}
valid = validate_recipients(recp);
if (valid->num_error != 0) {
cprintf("599 5.1.1 Error: %s\r\n", valid->errormsg);
- free(valid);
+ free_recipients(valid);
return;
}
if (CC->logged_in) {
if (CtdlCheckInternetMailPermission(&CC->user)==0) {
cprintf("551 5.7.1 <%s> - you do not have permission to send Internet mail\r\n", recp);
- free(valid);
+ free_recipients(valid);
return;
}
}
if ( (SMTP->message_originated_locally == 0)
&& (SMTP->is_lmtp == 0) ) {
cprintf("551 5.7.1 <%s> - relaying denied\r\n", recp);
- free(valid);
+ free_recipients(valid);
return;
}
}
strcat(SMTP->recipients, recp);
SMTP->number_of_recipients += 1;
if (valid != NULL)
- free(valid);
+ free_recipients(valid);
}
/* Clean up */
CtdlFreeMessage(msg);
- free(valid);
+ free_recipients(valid);
smtp_data_clear(); /* clear out the buffers now */
}
struct recptypes *valid;
int successful_bounce = 0;
static int seq = 0;
+ char *omsgtext;
+ size_t omsgsize;
+ long omsgid = (-1);
lprintf(CTDL_DEBUG, "smtp_do_bounce() called\n");
strcpy(bounceto, "");
give_up = 1;
}
+ /* Start building our bounce message */
+
bmsg = (struct CtdlMessage *) malloc(sizeof(struct CtdlMessage));
if (bmsg == NULL) return;
memset(bmsg, 0, sizeof(struct CtdlMessage));
bmsg->cm_fields['U'] = strdup("Delivery Status Notification (Failure)");
bmsg->cm_fields['M'] = malloc(1024);
-
strcpy(bmsg->cm_fields['M'], "Content-type: multipart/mixed; boundary=\"");
strcat(bmsg->cm_fields['M'], boundary);
strcat(bmsg->cm_fields['M'], "\"\r\n");
strcpy(bounceto, addr);
}
- if (
- (!strcasecmp(key, "local"))
- || (!strcasecmp(key, "remote"))
- || (!strcasecmp(key, "ignet"))
- || (!strcasecmp(key, "room"))
- ) {
+ if (!strcasecmp(key, "msgid")) {
+ omsgid = atol(addr);
+ }
+
+ if (!strcasecmp(key, "remote")) {
if (status == 5) bounce_this = 1;
if (give_up) bounce_this = 1;
}
}
}
- /* Attach the original message
- strcat(bmsg->cm_fields['M'], "--");
- strcat(bmsg->cm_fields['M'], boundary);
- strcat(bmsg->cm_fields['M'], "\r\n");
- strcat(bmsg->cm_fields['M'], "Content-type: application/octet-stream\r\n\r\n");
- strcat(bmsg->cm_fields['M'], "all your message are belong to FIXME\r\n");
- */
-
+ /* Attach the original message */
+ if (omsgid >= 0) {
+ strcat(bmsg->cm_fields['M'], "--");
+ strcat(bmsg->cm_fields['M'], boundary);
+ strcat(bmsg->cm_fields['M'], "\r\n");
+ strcat(bmsg->cm_fields['M'], "Content-type: message/rfc822\r\n");
+ strcat(bmsg->cm_fields['M'], "Content-Transfer-Encoding: 7bit\r\n");
+ strcat(bmsg->cm_fields['M'], "Content-Disposition: inline\r\n");
+ strcat(bmsg->cm_fields['M'], "\r\n");
+
+ CC->redirect_buffer = malloc(SIZ);
+ CC->redirect_len = 0;
+ CC->redirect_alloc = SIZ;
+ CtdlOutputMsg(omsgid, MT_RFC822, HEADERS_ALL, 0, 1, NULL);
+ omsgtext = CC->redirect_buffer;
+ omsgsize = CC->redirect_len;
+ CC->redirect_buffer = NULL;
+ CC->redirect_len = 0;
+ CC->redirect_alloc = 0;
+ bmsg->cm_fields['M'] = realloc(bmsg->cm_fields['M'],
+ (strlen(bmsg->cm_fields['M']) + omsgsize + 1024) );
+ strcat(bmsg->cm_fields['M'], omsgtext);
+ free(omsgtext);
+ }
+
+ /* Close the multipart MIME scope */
strcat(bmsg->cm_fields['M'], "--");
strcat(bmsg->cm_fields['M'], boundary);
strcat(bmsg->cm_fields['M'], "--\r\n");
/* Free up the memory we used */
if (valid != NULL) {
- free(valid);
+ free_recipients(valid);
}
}
completed = 0;
- if (
- (!strcasecmp(key, "local"))
- || (!strcasecmp(key, "remote"))
- || (!strcasecmp(key, "ignet"))
- || (!strcasecmp(key, "room"))
- ) {
+ if (!strcasecmp(key, "remote")) {
if (status == 2) completed = 1;
else ++incomplete;
}
lprintf(CTDL_DEBUG, "Performing SMTP cleanup hook\n");
free(SMTP);
- free(SMTP_ROOMS);
- free(SMTP_RECPS);
}
CtdlRegisterServiceHook(config.c_smtp_port, /* SMTP MTA */
NULL,
- smtp_greeting,
+ smtp_mta_greeting,
smtp_command_loop,
NULL);