masqmail

diff src/smtp_in.c @ 117:5ec5e6637049

added server-side SMTP SIZE support (patch by Paolo) ``SIZE 0'' (= unlimited) is currently not supported client-side support was already implemented
author meillo@marmaro.de
date Thu, 01 Jul 2010 13:08:53 +0200
parents 71ce3a1568e9
children cd59a5b4d3dd
line diff
     1.1 --- a/src/smtp_in.c	Wed Jun 30 15:45:34 2010 +0200
     1.2 +++ b/src/smtp_in.c	Thu Jul 01 13:08:53 2010 +0200
     1.3 @@ -55,8 +55,29 @@
     1.4  	return SMTP_ERROR;
     1.5  }
     1.6  
     1.7 +static gboolean
     1.8 +get_size(gchar *line, unsigned long *msize) {
     1.9 +	gchar *s = NULL;
    1.10 +
    1.11 +	/* hope we need not to handle cases like SiZe= ...*/
    1.12 +	s = strstr(line, "SIZE=");
    1.13 +	if (!s) {
    1.14 +		/* try it in lowercase too */
    1.15 +		if (!(s = strstr(line, "size="))) {
    1.16 +			return FALSE;
    1.17 +		}
    1.18 +	}
    1.19 +	s += 5;
    1.20 +	*msize = atol(s);
    1.21 +	DEBUG(5) debugf("get_size(): line=%s, msize=%ld\n", line, *msize);
    1.22 +
    1.23 +	return TRUE;
    1.24 +}
    1.25 +
    1.26 +
    1.27  /* this is a quick hack: we expect the address to be syntactically correct
    1.28 -   and containing the mailbox only:
    1.29 +   and containing the mailbox only, though we first check for size in
    1.30 +   smtp_in().
    1.31  */
    1.32  static gboolean
    1.33  get_address(gchar * line, gchar * addr)
    1.34 @@ -135,6 +156,7 @@
    1.35  	message *msg = NULL;
    1.36  	smtp_connection *psc;
    1.37  	int len;
    1.38 +	unsigned long size, msize;
    1.39  
    1.40  	DEBUG(5) debugf("smtp_in entered, remote_host = %s\n", remote_host);
    1.41  
    1.42 @@ -168,7 +190,7 @@
    1.43  
    1.44  			if (psc->prot == PROT_ESMTP) {
    1.45  				smtp_printf(out, "250-%s Nice to meet you with ESMTP\r\n", conf.host_name);
    1.46 -				/* not yet: fprintf(out, "250-SIZE\r\n"); */
    1.47 +				smtp_printf(out, "250-SIZE %d\r\n", conf.max_msg_size);
    1.48  				smtp_printf(out, "250-PIPELINING\r\n" "250 HELP\r\n");
    1.49  			} else {
    1.50  				smtp_printf(out, "250 %s pretty old mailer, huh?\r\n", conf.host_name);
    1.51 @@ -176,6 +198,15 @@
    1.52  			break;
    1.53  
    1.54  		case SMTP_MAIL_FROM:
    1.55 +			if (get_size(buffer, &msize)) {
    1.56 +				DEBUG(5) debugf("smtp_in(): get_size: msize=%ld, conf.mms=%d\n",
    1.57 +				                msize, conf.max_msg_size);
    1.58 +				if (msize > conf.max_msg_size) {
    1.59 +					smtp_printf(out, "552 Message size exceeds fixed limit.\r\n");
    1.60 +					break;
    1.61 +				}
    1.62 +			}
    1.63 +
    1.64  			{
    1.65  				gchar buf[MAX_ADDRESS];
    1.66  				address *addr;
    1.67 @@ -278,12 +309,18 @@
    1.68  
    1.69  			err = accept_message(in, msg, conf.do_save_envelope_to ? ACC_SAVE_ENVELOPE_TO : 0);
    1.70  			if (err != AERR_OK) {
    1.71 -				if (err == AERR_TIMEOUT || err == AERR_EOF) {
    1.72 +				switch (err) {
    1.73 +				case AERR_TIMEOUT:
    1.74 +				case AERR_EOF:
    1.75 +					return;
    1.76 +				case AERR_SIZE:
    1.77 +					smtp_printf(out, "552 Error: message too large.\r\n");
    1.78 +					return;
    1.79 +				default:
    1.80 +					/* should never happen: */
    1.81 +					smtp_printf(out, "451 Unknown error\r\n");
    1.82  					return;
    1.83  				}
    1.84 -				/* should never happen: */
    1.85 -				smtp_printf(out, "451 Unknown error\r\n");
    1.86 -				return;
    1.87  			}
    1.88  
    1.89