# Forwarding mail to MH format



## ekvz (Oct 10, 2020)

Recently i've been looking for a way to by able to read my local mail using mail/sylpheed which from what i understand only supports the _MH format_. While searching around i stumbled across some instructions on how to setup a forward that would convert the mails to said _MH format_ by using a tool called `rcvstore` which is provided by mail/nmh. Now the instructions i have read were targeted at mail/exim but forward(5) seemed to suggest that `sendmail` would support the exact same syntax so i followed said instructions which went like this:

Run `install-mh` which resulted in the following .mh_profile being created in the users home directory (the user i am trying to set this up for is root and i've actually created the path shown below):


```
MH-Profile-Version: 1.0
Path: /var/sysmail
```

Create .forward in the users home directory to forward the incoming mail to rcvstore (which on FreeBSD seems to be located at /usr/local/libexec/nmh/rcvstore) with the resulting file looking like this:


```
"|/usr/local/libexec/nmh/rcvstore"
```

Easy enough one would think. Sadly there seems to be some kind of problem i can't figure out or even know how to debug: As soon as the .forward is in place and i try to send mail to root the following (or similar) error shows up in /var/log/messages:


```
Oct 10 15:09:50 fdesk sm-mta[61329]: 09AD9owx061329: Losing ./qf09AD9owx061329: savemail panic
Oct 10 15:09:50 fdesk sm-mta[61329]: 09AD9owx061329: SYSERR(root): savemail: cannot save rejected email anywhere
```

I figure this might be related to `sendmail` simply not being mail/exim but i'd rather not replace the whole mail system just to get this working. Also forward(5) seems to suggest that `sendmail` also should be able to do this so i wonder if there is an obvious error somewhere. Any help would be greatly appreciated as i honestly don't even know where or how i could get any further info about what's going wrong. As is the error simply seems to tell me that delivery "didn't work" and that this "is bad" but gives little clue as to what's the actual cause for this.

Edit: I've already tried changing permissions on /var/sysmail to world-writable/readable to see if there might be a problem with this but it didn't make any difference and the error shown above appeared as soon is a tried sending mail to root. I've also tried removing the double-quotes from the .forward as this was how the mail/exim example was showing it but again the result stayed the same.


----------



## laurentis (Oct 10, 2020)

It's been a while since I used nmh but I think you can use the slocal() utility as a mail delivery agent to your .mh folder.


----------



## ekvz (Oct 10, 2020)

laurentis said:


> It's been a while since I used nmh but I think you can use the slocal() utility as a mail delivery agent to your .mh folder.



Thanks for the suggestion. While i don't really see what would be the advantage of using slocal over rcvstore i've tried using the example shown on the man page. Sadly it results in the same error as trying to forward to rcvstore. From poking around /var/log/maillog it seems like for some reson both of them exit with non zero exit code when invoked by sendmail. Piping data into them from the shell i can't replicate this (piping into rcvstore also actually results in the data being stored at the location defined .mh_profile). I always get a zero code whatever i do.

Trying to forward to a non existing binary actually results in exit code 127 being logged by sendmail which makes sense since that's what a shell reports for "file not found" i think. So it seems that sendmail at least tries to execute what is defined in .forward but why it would trigger an error even with the existing binaries sadly stays a mystery.


----------



## ekvz (Oct 11, 2020)

After some experiments and searching around the web i think i might have at least found where part of the issue stems from: As it turns out any application that is defined in .forward to have mail piped into it is not actually run as the user owning the .forward but rather as _mailnull_ and i guess the original issue of `rcvstore` exiting with an error code when run from .forward is because there obviously is no _$HOME_ set in the environment when run as _mailnull_ (and even if it was set it would be the wrong one) so it fails to find .mh_profile. Now making sure there _HOME_ is set pointing to /root wouldn't be much of a problem but also obviously won't solve anything as without being run as the user owning .forward the whole thing can't function.

I've looked into the sendmail configuration to see if there is an option to enable .forward to be executed as the owning user (which from what i read also seems to have been the default at some point) but my search came back inconclusive. While i suspect the change in behavior might be related to the often mentioned security improvements during sendmail 8.x and there are some instructions on how to revert them this seems a little excessive and i am not even sure if this would include executing .forward as the owning user. Does anyone maybe have some experience with this and is able to give me a pointer on how to proceed for having .forward as the owning user with as little (possibly security relevant) changes as possible?


----------

