Procmail recipe to match Spamassassin X-Spam-Status score or X-Spam-Level [closed] - procmail

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Consider these mail headers:
X-Spam-Level: ***
X-Spam-Status: Yes, score=3.7 required=3.0 tests= (remaining truncated for brevity)
I simply want to match the headers
"X-Spam-Level: ***" (at least with more "*" okay)
or
"X-Spam-Status: Yes, score=3.7" (or a higher score)
I have this, which matches the X-Spam-Level header, but I'm seeing stuff slip through with a score of 3.7 or higher, making me believe the alternation is being skipped:
:0 H
* ^X-Spam-Status: Yes
* ^(X-Spam-Level: \*\*\*\*)|(^X-Spam-Status: Yes, score=3\.[7-9])
{
do stuff
}
Procmail's regex implementation is just not quite the same as what I'm used to and can't get this to work, despite matching on sites like regex101.com
I'm perfectly fine with a solution just matching the score of 3.7 or higher and removing the X-Spam-Level condition completely.
Note: I am aware that the minimum score I've set in Spamassassin is 3.0 to flag as spam, however, I deliver stuff to the user's mailbox between 3 and 3.6 and move anything higher to a server spam mailbox. Presently, it's only getting delivered to the server's spam mailbox if 4.1 or higher, as denoted by the asterisks in X-Spam-Level.

I never could get this working. Instead, I modified the Spamassassin local.cf config to add a header line:
add_header all Score _SCORE_
This creates a new mail header of X-Spam-Score: n.n where n are digits.
In the procmailrc file, I added this line to the top:
# Change this value to be whatever threshold
# you want
# Spam scored between 3 and 3.6 will be delivered.
# Spam scored over 3.6 won't.
SPAMTHRESHOLD=3.6
Later in the file, after spamc is called, I declare a variable to capture the score then check against it:
# Create SCORE variable which contains the header I created in Spamassassin
:0 # H flag is implicit
* ^X-Spam-Score: \/.+
{ SCORE=$MATCH }
# Check for Spam-Status: Yes, and
# $SCORE > $SPAMTHRESHOLD
:0 H
* ^X-Spam-Status: Yes
* $ -${SPAMTHRESHOLD}^0
* $ ${SCORE}^0
{
# do stuff. in this case move the mail to
# /var/mail/spam
:0:spam.lock
/var/mail/spam
}

Related

Conditional Regex for Percentage based values [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
I've never been very good at regex, but I really need to grab the percentage information from these log entries; however, the warn/critical message moves around depending on where the warning was located in either the In or the Out utilization. I just can't figure out the regex. Here are two example entries that show both in and out issues:
["XXXXXXX"], (up), MAC: XX:XX:XX:XX:XX:XX, Speed: 2 GBit/s, In: 0 Bit/s (0%), Out: 6.53 GBit/s (warn/crit at 1.6 GBit/s/1.8 GBit/s) (326.45%)(!!)
["XXXXXXX"], (up), MAC: XX:XX:XX:XX:XX:XX, Speed: 2 GBit/s, In: 0 Bit/s (warn/crit at 1.6 GBit/s/1.8 GBit/s) (95.45%), Out: 6.53 GBit/s (32.00%)(!!)
Ultimately I need to use capture groups to capture both the in and out utilization percentage. But every regex I try only finds a single percentage. Help on this would be greatly appreciated. Thanks in advance.
EDIT SHOWING EXPECTED RESULT:
for each line the regex capture groups would identify in and out so the program can see both the in and out utilization. The program is expecting a key value pair from every log entry like the following:
IN:0% OUT:326.45%
IN:95.45% OUT:32.00%
Do you need something like this?
In:.+\(([0-9\.]+%)\).+Out:.+\(([0-9\.]+%)
If you just need to pull out values with percentage information, then it can help
https://regex101.com/r/B9pZeO/1

What is the right Regular Expression for my validation? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I created a RegEx-based validation with SO's help and passed it off to my coworker explaining the reasons why it is needed (Referring to it as a Whitelist). The coworker then proceeded to change my code (insisting upon what they called a Blacklist) and modified the RegEx. The code corresponding to each approach is listed below. The validation should ensure that only a hyphen, numbers, spaces and letters are allowed. I'd like to know
Which of the code fragments achieves that?
How can I break my co-worker's code?
Is a Blacklist just a Whitelist with the condition inverted?
My co-worker's Code:
objRegExp.Pattern= "[^-A-Za-z0-9'&(). ]"
if objRegExp.Test(strInput) then
FoundSpecialChar= true
exit function
end if
FoundSpecialChar= false
Set objRegExp = Nothing
My Code:
objRegExp.Pattern= "^[-A-Za-z0-9\s'&().]+"
if objRegExp.Test(strInput) then
FoundSpecialChar= false
exit function
end if
FoundSpecialChar= true
Set objRegExp = Nothing
Your colleague's approach lists the acceptable characters. If it finds even one character not in that list, it sets FoundSpecialChar= true which seems to be what you want. To test the difference between his code and yours, you could try to run both the code fragments with strInput = "ABCD#EFGH".
Running your code once with strInput = "A#" and another time with strInput = "#A" should help as well.
BTW, Set objRegExp = Nothing should be included before Exit Function as well.
I am from testing background and I've experienced that Whitelist approach is good from application developer point of view and Blacklist approach is good to test the application. The reason being, as a dev a Whitelist gives you control over the exact input that a user is allowed to enter. On the other hand, as a tester I would use the Blacklist approach more because it will have infinite number of options to test.
Interesting discussion on SO --> blacklisting vs whitelisting in form's input filtering and validation

Notepad++ find and replace after specific character [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have hundred of song lyric database files, and I need to do something like this,
from this :
PPK4: B'rilah Hormat Pada Hu
Judul Inggris: Glory to God in the Highest
Lagu: unknown Syair: unknown
1=A, 4/4
to become like this :
PPK4: B'rilah Hormat Pada Hu
B'rilah Hormat Pada Hu
Judul Inggris: Glory to God in the Highest
Lagu: unknown Syair: unknown
1=A, 4/4
PPK4 is a song number. so, there will be like PPK1 until PPK255, KPPK1 .. KPPK300 etc.
and same format, "#songcode" ":" "(space)" "song title" "CRLF"
How do I do it using Find and Replace?
The answer involves regular expressions.
You could try "([A-Z]+[0-9]+[:])(.*)"
This will capture the song number as group 1 and the song title as group 2. You can then replace this with "\1\2\n\2", i.e. group 1 followed by group 2, a newline and group 2 again.

Regex: finding a number between a range with decimals [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I can not for the life of me get my head around this regex stuff after a few days of fiddling around I find myself seeking help from those wiser than I. Could any of you kind souls write me a line(s) that will find and match a number between 0.00 and x.xx? I do need the decimals however so hopefully this can be done.
I actually tried using
(\b|^)(0.00|0.01|0.02)(\b|$)
until x.xx and so forth but I couldn't fit the rest of it in because I need it to go into the 100.00+. Would anyone mind whipping something up real quick for me? : ) I would appreciate it more than you can imagine! Thanks very much for your time.
Ray.
Edit:
So i forgot to explain what I'm trying to achieve here, I'm using it in conjunction with a Chrome addon called Page Monitor (life saver folks try it out when you have time to kill!) which pings every time an a website updates, this also works for shares but I'm trying to make it only alert me when the price drops below a certain point eg $4.99 per share, will (\b|^)([0-9]+\.[0-9]{2})(\b|$) and ([0-9]+.[0-9]+) suffice?
Why isn't this good enough: ([0-9]+\.[0-9]+) ?
If you can give an example of input and what is the output you expect, it would be easier to write a regex.
Updated: $ sign is a reserved character in RegEx, it means end-of-line, so you need to use \$, if you plan on using it.
So your regex would be \$([0-9]+\.[0-9]+), this would capture your $4.99 and $5.10, etc, not just $4.99
Regexs in general are good at capturing data, less at analyzing it, but if you must, you can do this to determine when the price goes below $4.99 =>
\$(([0-3]\.[0-9]+)|(4\.[0-8][0-9])|(4\.9[0-8]))
It should be obvious that its a waste of resource :)
Didn't provide enough info but this will match if the number is the entire value or if it is within a larger string and the number is not withing something else like "foo8.9bar". This will match any 1 or more digit number on the left side of the decimal and exactly 2 numbers on the right side
(\b|^)([0-9]+\.[0-9]{2})(\b|$)
(\b|^) and (\b|$) are redundant because \b implies ^ and $.
this regex: (\d+\.\d{2}) should do it.

Use grep to list the files a directory that were changed less that 10 hours ago [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I found this exercise from here
Make a list of files in your home directory that were changed less that 10 hours ago, using grep, but leave out directories.
It seems trivial to use find command, but how do I use grep command to find files that were changed within last 10 hours?
Thanks!
Okay, this is an abomination, but it is an exercise and I was curious. The regex is likely too simple, but it works in my test case. The "trick" here is that I'm using "stat" instead of "ls". With "stat", you can request particular fields ( including last modified date ) and format the output. Here I'm grabbing the current timestamp, going back 10 hours and then funneling stat formatted for mode in string form, modified date timestamp and filename through grep:
sh-3.2$ date "+%s"
1373170496
sh-3.2$ bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1373170496-36000
1373134496
sh-3.2$ stat -f"%Sp %m %N" * | grep "^[\-].*13731[3-7][0-9][0-9][0-9][0-9].*$"
-rw-r--r-- 1373168941 fileAB
-rw-r--r-- 1373168944 fileAC
Where fileAB and fileAC are two empty files I touched for some representative data. The matches show the stat output, which is better explained by man pages.
The question is taken from the Bash Guide for Beginners, Chapter 4. Regular expressions. It is not a practical question, it's obviously going for exercising regular expressions, in a somewhat twisted way. Furthermore, the book is hosted on The Linux Documentation Project's site, so it is probably safe to assume to implement this in Linux, using the GNU implementation of the usual tools.
Here's my solution, using grep (a little bit):
ls -algG --time-style=+%s | grep ^[^d] | awk -vlimit=$(date +%s -d '10 hours ago') '$4 > limit { print substr($0, index($0, $4) + length($4) + 1) }'
Explanation:
The ls options are to list all files including hidden ones (-a), use the long format (-l), omit owner and group information (-g, -G), and format times as if interpreted by date, %s means seconds since 1970-01-01 00:00:00 UTC
The grep matches lines that start with other than the letter "d", effectively excluding directories
We pipe this to awk, because quite frankly there's no reasonable way to bend regular expressions for matching dates that stand for "less than 10 hours ago"
In the real world, I would solve this problem like this, NOT using regular expressions:
touch marker.touch -d '10 hours ago'
find . -newer marker.touch -maxdepth 1 -type f