# Fetchmail: Adding a header before passing on

## chaz

I am using fetchmail to receive mail from a few external servers. It then sends them on to postfix and are then delivered by maildrop to virtual users. What I would like to be able to do is, add a header "X-SourceServer:" set to a value that indicates which server fetchmail received the message from, before passing the message on to postfix.

My thought had been to use the fetchmailrc Delivery Control Options to set the "mda" to pipe through reformail before passing to maildrop, bypassing postfix altogether.  However I have no idea how I would do that (or if I even can) as postfix takes care of figuring out "who" the mail goes to, and passing that to maildrop.

Any ideas on how this could be done, in this or any other manor?

Thanks

Chaz

----------

## nielchiano

 *chaz wrote:*   

> What I would like to be able to do is, add a header "X-SourceServer:" set to a value that indicates which server fetchmail received the message from, before passing the message on to postfix.

 

not exactly what you asked for, but fetchmail does some of this already: *man fetchmail wrote:*   

> The --invisible option (keyword: set invisible) tries to make fetchmail invisible.  Normally, fetchmail behaves like any other MTA would -- it  generates a  Received  header  into  each  message  describing its place in the chain of transmission, and tells the MTA it forwards to that the mail came from the machine fetchmail itself is running on.  If the invisible option is on, the Received header is suppressed and fetchmail tries to spoof the  MTA  it  forwards to into thinking it came directly from the mailserver host.

 

it looks like this (mangled to protect privacy)

```
Received: from pop.blabla.tld [1.2.3.4]

   by mailserver.homenetwork.tld with POP3 (fetchmail-6.3.2)

   for <me@mydom.tld> (single-drop); Thu, 34 Jun 2009 26:62:71 +0200 (CEST)
```

----------

## chaz

 *Quote:*   

> man fetchmail wrote:
> 
> The --invisible option (keyword: set invisible) tries to make fetchmail invisible. Normally, fetchmail behaves like any other MTA would -- it generates a Received header into each message describing its place in the chain of transmission, and tells the MTA it forwards to that the mail came from the machine fetchmail itself is running on. If the invisible option is on, the Received header is suppressed and fetchmail tries to spoof the MTA it forwards to into thinking it came directly from the mailserver host.

 

Thanks for that.  That would be close, but if I do that, I loose the IP address of the real server in the Received header.

Instead of getting -> Received: from pop.blabla.tld [1.2.3.4] 

It shows as -> Received: from pop.blabla.tld  (localhost [127.0.0.1])  

(which is the IP of the machine fetchmail runs on)

I guess that does not realy matter though, since I know I've made the connection to pop.blabla.tld and likely don't need the real IP in this case.

----------

## nielchiano

 *chaz wrote:*   

>  *Quote:*   man fetchmail wrote:
> 
> The --invisible option (keyword: set invisible) tries to make fetchmail invisible. Normally, fetchmail behaves like any other MTA would -- it generates a Received header into each message describing its place in the chain of transmission, and tells the MTA it forwards to that the mail came from the machine fetchmail itself is running on. If the invisible option is on, the Received header is suppressed and fetchmail tries to spoof the MTA it forwards to into thinking it came directly from the mailserver host. 
> 
> Thanks for that.  That would be close, but if I do that, I loose the IP address of the real server in the Received header.
> ...

 

no, the 1.2.3.4 is the IP of pop.blabla.tld

the received line above it DOES show received from localhost, because then postfix is receiving the mail from fetchmail:

```

Received: from mailserver.homenetwork.tld (mailserver [127.0.0.1])

   by mailserver.homenetwork.tld (Postfix) with ESMTP id 3D54205A687

   for <me@mydom.tld>; Thu, 34 Jun 2009 26:62:72 +0200 (CEST)

Received: from pop.blabla.tld [1.2.3.4]

   by mailserver.homenetwork.tld with POP3 (fetchmail-6.3.2)

   for <me@mydom.tld> (single-drop); Thu, 34 Jun 2009 26:62:71 +0200 (CEST)
```

----------

## chaz

Let me clarify

Headers when set invisible=NOT set:

```
Return-Path: <XXX@XXXXXXalm.com>

X-Spam-Checker-Version: SpamAssassin 3.1.0-gr0 (2005-09-13) on ruby.inet

X-Spam-Level: 

X-Spam-Status: Spam=No, score=0.0 required=5.0 tests=none autolearn=ham

Delivered-To: XXX@XXXXXXalm.net

Received: from ruby (localhost [127.0.0.1])

     by mail.ruby.inet (Postfix) with ESMTP id DFDD5521E4

     for <XXX@XXXXXXalm.net>; Thu, 22 Jun 2006 12:35:07 -0400 (EDT)

Envelope-to: me@remotesystem.com

Delivery-date: Thu, 22 Jun 2006 10:27:43 -0600

Received: from mail.remotesystem.com [70.98.xxx.43]

     by ruby with IMAP (fetchmail-6.3.2)

     for <XXX@XXXXXXalm.net> (single-drop); Thu, 22 Jun 2006 12:35:07 -0400 (EDT)

Received: from qsisyste by box43.remotesystem.com with local-bsmtp (Exim 4.52)

     id 1FtS1u-0002PX-9y

     for me@remotesystem.com; Thu, 22 Jun 2006 10:27:42 -0600

```

Headers when set invisible=set:

```
Return-Path: <XXX@XXXXXXalm.com>

X-Spam-Checker-Version: SpamAssassin 3.1.0-gr0 (2005-09-13) on ruby.inet

X-Spam-Level:

X-Spam-Status: Spam=No, score=0.0 required=5.0 tests=none autolearn=ham

Delivered-To: XXX@XXXXXXalm.net

Received: from mail.remotesystem.com (localhost [127.0.0.1])

     by mail.ruby.inet (Postfix) with ESMTP id 5912651A12

     for <XXX@XXXXXXalm.net>; Thu, 22 Jun 2006 12:30:03 -0400 (EDT)

Envelope-to: me@remotesystem.com

Delivery-date: Thu, 22 Jun 2006 10:23:32 -0600

Received: from qsisyste by box43.remotesystem.com with local-bsmtp (Exim 4.52)

     id 1FtRxr-0001Qn-Fz

     for me@remotesystem.com; Thu, 22 Jun 2006 10:23:32 -0600

```

In the first block the remote mail server is shown with proper correct ip

Received: from mail.remotesystem.com [70.98.xxx.43]

In the 2nd the remote mail server has the correct name but the IP is lost

Received: from mail.remotesystem.com (localhost [127.0.0.1])

I'm guessing that this is a problem with fetchmail being able to spoof the server name but, not able to fool postfix into not using the IP of the sending machine which it seems to "Know" is the local host. (where fetchmail is running)

But I'm not going to worry about it because thanks to your input, looking at the headers I found I could simply add a .mailfilter rule to maildrop that checks for the server name and adds a header when required.  It won't scale well but then again it does not have to. For this deployment anyway.

----------

