Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions esmtprc.5
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ The host-port notation simplifies things for the application, the user can
type "localhost:smtp" or "localhost:25" where the application
expects a host name.

.TP
\fBsender\fR
Set the identity of the sender of the email.

This is useful for systems behind a NAT firewall, when for example
the sender's email address should not have the hostname. Several
escape formatting codes are available:

%u - user name of the sender
%h - hostname of the sending system
%d - domainname of the sending system

So %u@%d might be a desirable identity from inside the local network.

.TP
\fBusername\fR
Set the username for authentication with the SMTP server.
Expand Down
1 change: 1 addition & 0 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ statement_list : statement

/* future global options should also have the form SET <name> optmap <value> */
statement : HOSTNAME map STRING { identity->host = xstrdup($3); SET_DEFAULT_IDENTITY; }
| SENDER map STRING { identity->address = xstrdup($3); }
| USERNAME map STRING { identity->user = xstrdup($3); SET_DEFAULT_IDENTITY; }
| PASSWORD map STRING { identity->pass = xstrdup($3); SET_DEFAULT_IDENTITY; }
| STARTTLS map DISABLED { identity->starttls = Starttls_DISABLED; SET_DEFAULT_IDENTITY; }
Expand Down
75 changes: 72 additions & 3 deletions smtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,67 @@ static char *escape_forced_address (char *mask)

}

/* search for end of string */
static inline char *eos(char *p)
{
while (*p) p++;
return p;
}

/* substitute %codes in a string,
%u = get_username()
%h = gethostname()
%d = domainname (omit host. in host.domain.name from gethostname)
return the result in a newly malloced string
*/
char *xstrsubst(char *pp,char *p)
{
char address[2048],*dp=address;
while (p)
{
strcpy(dp,pp);
dp += (p - pp);
switch (p[1])
{
case 'u':;
strcpy(dp,get_username());
dp = eos(dp);
p += 2;
break;

case 'h':;
if(! gethostname(dp,sizeof(address)-(dp-address)))
dp = eos(dp);
p += 2;
break;

case 'd':
if(! gethostname(dp,sizeof(address)-(dp-address)))
{
char *pt = strchr(dp,'.');
if (pt++)
{
do { *dp++ = *pt++; } while (*pt);
}
else
dp = eos(dp);
}

p += 2;
break;

default:
fprintf(stderr,"unknown formatter in sender %s\n",p);
return 0;
}
pp = p;
p = strchr(pp,'%');
}

strcpy(dp,pp);
return xstrdup(address);
}

void smtp_send(message_t *msg, identity_t *identity)
{
smtp_session_t session;
Expand Down Expand Up @@ -597,9 +658,17 @@ void smtp_send(message_t *msg, identity_t *identity)
}
else if(identity->address)
{
/* Use the identity address as reverse path. */
if(!smtp_set_reverse_path (message, identity->address))
goto failure;
char *p=strchr(identity->address,'%');
if (p)
{ /* expand %codes in address */
char *av = xstrsubst(identity->address,p);
if (! av) goto failure;
free(identity->address);
identity->address = av;
}
/* Use the identity address as reverse path. */
if(!smtp_set_reverse_path (message, identity->address))
goto failure;
}
else
{
Expand Down