Wednesday, December 22, 2021

Re: opensmtpd remove messages from/to specified mailbox?

> On Dec 22, 2021, at 21:48, kasak <kasak@kasakoff.net> wrote:
>
> i'm afraid your magic is much more dark than mine!

I wouldn't call 'awk' dark magic.

> doas mailq | grep administrator.com <http://administrator.com/> | cut -f 1 -d "|" - | xargs -n1 doas smtpctl remove
> But with my example i sure can't delete messages from "@" so, your magic is more powerfull! Thumbs up for that!


The problem with your mechanism is you're grepping for @administrator.com, which can match any part of the line. That is the unsafe part.

If you want a safer, not-so-dark magic, version then split out the bits you want to check, and then check that field. Since awk is out, use another regex check once you've cut it down the the field you care about. To delete messages from "@":

mailq | cut -d\| -f1,5 | grep '|@$' | cut -d\| -f1 | xargs …

Note in building these pipelines, it's good to check each step as you to to ensure you're doing the right thing. :-)

Sean

> 23.12.2021 00:52, Sean Kamath пишет:
>> Aside from the lazy 'grep administrator.com' bit. . . yeah.
>>
>> I often do some variation on (as root in a script):
>>
>> smtpctl show queue | awk -F\| '$3 == "mta" && $5 == "@" {print $1}' | xargs -n1 smtpctl remove
>>
>> to remove unbouncable junk. This is much more flexible than adding a bunch of options to 'remove' to remove some regex/match/DSL thingie.
>>
>> Sean
>>
>> PS You can use regex matching instead of '==' in my sample line.
>>
>>> On Dec 22, 2021, at 05:25, kasak <kasak@kasakoff.net> wrote:
>>>
>>> Hello misc! How do you clean messages for one mailbox?
>>>
>>> for example, i have this in my queue:
>>>
>>> 2cce379a666925bc|local|mta|auth|@|info@administrator.com|info@administrator.com|1640178598|1640178598|1640178598|0|inflight|24|
>>> 3c712effebd6fe5a|local|mta|auth|@|bounce-860-17875544-860-248@yplinyi02.cn|bounce-860-17875544-860-248@yplinyi02.cn|1640140496|1640140496|0|10|pending|1874|Network error on destination MXs
>>> 90f946248731d1d9|local|mta|auth|@|info@administrator.com|info@administrator.com|1640178200|1640178200|1640178600|1|inflight|22|Network error on destination MXs
>>> 98eb22222ef2094f|local|mta|auth|@|info@administrator.com|info@administrator.com|1640177337|1640177337|0|2|pending|315|Network error on destination MXs
>>>
>>> now i want to remove all messages from @administrator.com.
>>>
>>> this is how it can be done:
>>>
>>> ----------
>>>
>>> for i in `doas smtpctl show queue | grep administrator.com | awk -F "|" '{print $1}'`
>>>
>>> doas smtpctl remove $i
>>>
>>> ----------
>>>
>>> It works, but the whole concept is just scary! Usually i try to avoid such bulky constructions.
>>>
>>> Maybe I missed something, and it can be made easier ?

No comments:

Post a Comment