On 4 Mar 2019, at 6:58, Vsevolod Stakhov wrote:

Hello,

I'm trying to debug one issue with the milter interface in Postfix. I
want to remove multiple headers with the same name, for example:

X-Spam-Flag: No
X-Spam-Flag: No
X-Spam-Flag: Not really
X-Spam-Flag: No

To do that, I track headers on header phase and track numbers for each
header. For this particular sample, I will have some map like
`X-Spam-Flag = 4`.

After end-of-data stage, I send multiple `CHGHEADER` ('m') commands with
header value equal to a empty string:

change/insert header command pos = 1 - "X-Spam-Flag"=""
change/insert header command pos = 2 - "X-Spam-Flag"=""
change/insert header command pos = 3 - "X-Spam-Flag"=""
change/insert header command pos = 4 - "X-Spam-Flag"=""

Literally, my code (Rspamd) sends CHGHEADER command 4 times. After
message being processed, I can see that Postfix removes 2 of 4
`X-Spam-Flag` headers.

I have tested something else after that. I have tried to add more
headers where names are equal and non equal. It seems that all odd
headers are not removed.

I have not tested this, but your description is consistent with the Milter interface acting immediately on your deletion of the indexed header instance and collapsing the array, modifying which index points to which data. So, after you delete the 1st "X-Spam-Flag" header, you now have 3 instances remaining, with the new 1st instance being the former 2nd instance. This way, if you delete the 2nd instance, you are deleting what WAS the 3rd.

In any event, the results described also imply that you are not bothering to check for errors when you call a library routine that CAN return an error. Again, I have not tested this but I know that chgheader CAN return an error and would expect it to do so when passed an out-of-range index.

Return values exist for good reasons. One of them is to help novice coders avoid public embarrassment.

--
Bill Cole
b...@scconsult.com or billc...@apache.org
(AKA @grumpybozo and many *@billmail.scconsult.com addresses)
Available For Hire: https://linkedin.com/in/billcole

Reply via email to