0

How do I get procmail to save messages in my Maildir folder, but not include the hostname in the file (message name)? I get the following message names in my new/ sub-folder:

  1464003587.H805375P95754.gator3018.hostgator.com, S=20238_2

I just want to eliminate the hostname. Is that possible to do, using procmail? How? Separately, it is possible to replace the first time stamp with the time-sent time-stamp? Is it possible to prescribe a format for procmail?

tripleee
  • 175,061
  • 34
  • 275
  • 318
user3236841
  • 1,088
  • 1
  • 15
  • 39

1 Answers1

0

No, you can't override Maildir's filename format, not least because it's prescribed to be in a particular way for interoperability reasons. The format is guaranteed to be robust against clashes when multiple agents on multiple hosts concurrently write to the same message store. This can only work correctly if they all play by the same rules. An obvious part of those rules is the one which dictates that the host name where the agent is running must be included in the filename of each new message.

The Wikipedia Maildir article has a good overview of the format's design and history, and of course links to authoritative standards and other primary sources.

If you don't particularly require Maildir compatibility (with the tmp / new / cur subdirectories etc) you can simply create a unique mbox file on each run; if you can guarantee that it is unique, you don't need locking when you write to it.

For example, if you have a tool called uuid which generates a guaranteed unique identifier on each invocation, you can use that as the file name easily;

:0  # or maybe :0r
`uuid`

It should be easy to see how to supply your own tool instead, if you really think you can create your own solution for concurrent delivery. (Maildir solves concurrent and distributed delivery, so the requirements for that are stricter.)

The other formats supported by Procmail have their own hardcoded rules for how file names are generated, though perhaps the simple MH folder format, with a (basically serially incrementing) message number as the file name, would be worth investigating as well. The old mini-FAQ has a brief overview of the supported formats and how to select which one Procmail uses for delivery in each individual recipe.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Thanks! Edited to ask if I can use the generic localhost.localdomain. Also, what is in a .mh_sequence of an MH folder? I have found it difficult to find this answer. – user3236841 Oct 17 '20 at 13:18
  • I guess it's a sequence number; I don't think anybody is using MH any longer. Editing the question after you have received an answer is not good form; I guess you'd have to use `LD_PRELOAD` to redirect whatever system call Procmail is using to get the host name. – tripleee Oct 17 '20 at 13:22
  • Oh, sorry about that: I have noticed that most people do this, so I figured that that is the way to go. Where do I set the LD_PRELOAD for use with procmail (and perhaps mutt) only? Also, if you edit your answer to include the additional information, perhaps it may be easier for more people to benefit. (I will accept it anyway). Thanks again! – user3236841 Oct 17 '20 at 13:48
  • Overriding system calls with `LD_PRELOAD` requires you to write your own C program to override the system call so it's significantly outside of anything related to Procmail *per se.* I believe the `fakeroot` author wrote an intro about this technique but that was many years ago; quick googling gets me a fresh tutorial at https://catonmat.net/simple-ld-preload-tutorial – tripleee Oct 17 '20 at 15:31
  • Thanks very much! Interesting article and very helpful. so, I should write a wrapper in C to set LD_PRELOAD then call procmail perhaps? I will think about this some more. Or perhaps MH is what I will settle with. Thanks again! – user3236841 Oct 17 '20 at 15:36
  • Yeah, you'd override `gethostbyname()` or whatever Procmail is calling (you can check wrth `strace` on Linux) to always return `localhost.localdomain` or whatever you prefer, and hook it up around Procmail and anything else which wants to create a Maildir file name. – tripleee Oct 17 '20 at 15:42
  • This is very interesting, thank you very much again! – user3236841 Oct 17 '20 at 16:04
  • I'll caution again against mucking with internal things for what appears to be pure aesthetics. If you need things to be a particular way for a specific use case, maybe write a separate script which maps your Maildir folder structure into whatever labels you need for that specific set of tasks. – tripleee Oct 18 '20 at 07:18