Re: Matching literal dot in To
Chuck Martin <[email protected]> Fri, 12 Jun 2015 21:11:31 -0400
| Newsgroups | gmane.mail.procmail |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Jun 12, 2015 at 06:50:52PM -0500, Moby wrote: > On 06/12/2015 04:56 PM, Chuck Martin wrote: > >On Fri, Jun 12, 2015 at 04:02:27PM -0500, Moby wrote: > >>:0w > >>* ^To:.*\..*@.* > >>| $DELIVERTO -a $CYUSER -m "jdotrejects" $CYUSER > >> > >>The log snippet is: > >>procmail: Match on "^To:.*\..*@.*" > >> > >>Here are header snippets from the particular email: > >> > >>From: "GameStop PowerUp Rewards" <[email protected]> > >>To: "[email protected]" <[email protected]> > >I see your problem here. Look at that last line, and how it matches > >your pattern: > > > >> To: "[email protected]" <[email protected]> > > \_/\________________/^\____________/^\__________/ > > ^To: .* \. .* @ .* > > > Many thanks. I see the issue now - but cannot think of an easy fix short of > sending the message to an external script for processing. Would you have any > ideas on how to handle situations like this? I now realize > I would also need to handle the case where the To: line has multiple > recipients, I would need to check ~each~ email address as to whether it has > a dot in it or not. For a single address, you could put this somewhere ahead of the recipe: TO=`formail -cx 'To:' | sed -re 's/.*<(.*@[^ >]*)>.*/\1/;s/^ *//;s/ *$//'` That will extract the first address only, if there are multiple addresses in the "To:" line, and strip any whitespace from the beginning and/or end, if present (this may be the case if there were no angle brackets in the address, like if the address was alone, without a name). Then in the recipe itself, change this: * ^To:.*\..*@.* to this: * ? test -n "$TO" && grep '.*\..*@.*' "$TO" The 'test -n "$TO"' part makes sure $TO isn't empty, as it might be if there was no "To:" line in the header, and the grep looks for the dot in the address. If there are more addresses, then the question I would ask is what is it you're looking for exactly? Should it be considered a match if any address has a dot, or only if all of them have dots? What's your reason for checking for the dot? The solution depends on that answer, and could be pretty complex. By the way, my reply to you was supposed to go to the list, so I'm sending this to the list, where it should have been in the first place. My first attempt at replying to the list had the wrong address in the "From:" line (it wasn't the one used to subscribe to this list, and I think it got blocked), and when I tried to resend it, I did a regular reply instead of a list-reply. Sorry about that. -- This address uses a whitelist. If you aren't in my whitelist, you can only send me e-mail if you send to an appropriately tagged address (it includes +sometag between the username and @). Finger my untagged e-mail address for a tag guaranteed good for 24 hours if you're unsure. If I've sent you mail recently, you're temporarily whitelisted automatically.