Re: Extract Local-part from To: Adress to use in spamassassin rule

2024-05-23 Thread giovanni

On 5/23/24 5:39 PM, Bill Cole wrote:

On 2024-05-23 at 03:40:48 UTC-0400 (Thu, 23 May 2024 09:40:48 +0200)
Carsten 
is rumored to have said:


Hi @all,

I want to create a SpamAssassin rule that checks if the subject line of an email contains the local 
part of the recipient's email address (the part before the @ symbol). For example, if the 
recipient's email address is |i...@example.com|, I want to check if the subject contains the phrase 
"info lorem ipsum". If the recipient's email address is |foo...@example.com|, I want to 
check if the subject contains the phrase "foobar lorem ipsum". The rule should be general 
and adaptable to different local parts of email addresses.

*Requirements:*

1. Extract the local part of the recipient's email address from the
   |To| header.
2. Use the extracted local part to check if it is present in the
   |Subject| header.
3. The rule should be written in a way that works for any local part of
   the email address, not just a specific one.


See the section titled "CAPTURING TAGS USING REGEX NAMED CAPTURE GROUPS" in the 
embedded configuration documentation (perldoc Mail::SpamAssassin::Conf) for how to 
capture a pattern in one rule and use it in another. I don't have a working rule for you, 
but that's the mechanism I would use.


If you need same samples to start with, take a look at 
https://github.com/apache/spamassassin/blob/094428cf11b0ad8d5658fd18d62d69663357fb10/rulesrc/sandbox/gbechis/20_misc.cf#L98

  Giovanni



OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: Extract Local-part from To: Adress to use in spamassassin rule

2024-05-23 Thread Jimmy
Hi,

Try this

if (version >= 4.00)
 if can(Mail::SpamAssassin::Conf::feature_capture_rules)
   header   __TZ_CAP_TO_USR   To:addr =~ /(?[^@]+)/
   header   __TZ_SUBJ_HAS_USR Subject =~ /\b%{TZ_TO_USR}\b/i
 endif
endif

I'm curious if CAPTURING TAGS can handle multiple groups within the same
rules like this?

header   __TZ_CAP_TO_ADDR   To:addr =~
/(?)\@(?)/

Jimmy




On Thu, May 23, 2024 at 2:40 PM Carsten  wrote:

> Hi @all,
>
> I want to create a SpamAssassin rule that checks if the subject line of an
> email contains the local part of the recipient's email address (the part
> before the @ symbol). For example, if the recipient's email address is
> i...@example.com, I want to check if the subject contains the phrase
> "info lorem ipsum". If the recipient's email address is foo...@example.com,
> I want to check if the subject contains the phrase "foobar lorem ipsum".
> The rule should be general and adaptable to different local parts of email
> addresses.
>
> *Requirements:*
>
>1. Extract the local part of the recipient's email address from the To
>header.
>2. Use the extracted local part to check if it is present in the
>Subject header.
>3. The rule should be written in a way that works for any local part
>of the email address, not just a specific one.
>
> Thank you very much for your suggestions
>


Re: Extract Local-part from To: Adress to use in spamassassin rule

2024-05-23 Thread Bill Cole

On 2024-05-23 at 03:40:48 UTC-0400 (Thu, 23 May 2024 09:40:48 +0200)
Carsten 
is rumored to have said:


Hi @all,

I want to create a SpamAssassin rule that checks if the subject line 
of an email contains the local part of the recipient's email address 
(the part before the @ symbol). For example, if the recipient's email 
address is |i...@example.com|, I want to check if the subject contains 
the phrase "info lorem ipsum". If the recipient's email address is 
|foo...@example.com|, I want to check if the subject contains the 
phrase "foobar lorem ipsum". The rule should be general and adaptable 
to different local parts of email addresses.


*Requirements:*

1. Extract the local part of the recipient's email address from the
   |To| header.
2. Use the extracted local part to check if it is present in the
   |Subject| header.
3. The rule should be written in a way that works for any local part 
of

   the email address, not just a specific one.


See the section titled "CAPTURING TAGS USING REGEX NAMED CAPTURE GROUPS" 
in the embedded configuration documentation (perldoc 
Mail::SpamAssassin::Conf) for how to capture a pattern in one rule and 
use it in another. I don't have a working rule for you, but that's the 
mechanism I would use.




--
Bill Cole
b...@scconsult.com or billc...@apache.org
(AKA @grumpybozo@toad.social and many *@billmail.scconsult.com 
addresses)

Not Currently Available For Hire


Extract Local-part from To: Adress to use in spamassassin rule

2024-05-23 Thread Carsten

Hi @all,

I want to create a SpamAssassin rule that checks if the subject line of 
an email contains the local part of the recipient's email address (the 
part before the @ symbol). For example, if the recipient's email address 
is |i...@example.com|, I want to check if the subject contains the 
phrase "info lorem ipsum". If the recipient's email address is 
|foo...@example.com|, I want to check if the subject contains the phrase 
"foobar lorem ipsum". The rule should be general and adaptable to 
different local parts of email addresses.


*Requirements:*

1. Extract the local part of the recipient's email address from the
   |To| header.
2. Use the extracted local part to check if it is present in the
   |Subject| header.
3. The rule should be written in a way that works for any local part of
   the email address, not just a specific one.

Thank you very much for your suggestions