Why isn't booliean expression working - regex

I am using the following regular expression to filter some junk emails
\bNeotube\b | \bNeotubeTV\b
Here is a sample of the junk email header:
Return-path: <uranus#pschic.info>
Envelope-to: coben#jesusmylord.org
Delivery-date: Thu, 25 May 2017 14:18:58 +0200
Received: from [45.59.120.18] (port=30375 helo=pschic.info)
by ok1057.kvchosting.com with esmtp (Exim 4.89)
(envelope-from <uranus#pschic.info>)
id 1dDrj8-0002X1-Se
for coben#jesusmylord.org; Thu, 25 May 2017 14:18:58 +0200
From: "NeotubeTV" <uranus#pschic.info>
Date: Thu, 25 May 2017 06:58:18 -0500
MIME-Version: 1.0
Subject: Free TV shows, Sports and New Movies on your TV In HD?
To: <coben#jesusmylord.org>
Message-ID: `
The above expression does not work. However, if I just use
\bNeotubeTV\b
the email is filtered. Why doesn't the above OR statement work?
Thanks for your help.
Chris

It's because you have spaces around the | which is saying that you want include those spaces in your regex.

Related

how to pre-fix a piece of text in github "git log" using shell-script

I need to make a github commit (the text), from the git command git log into a link in an email. So the recipient can click on the link and go directly to the change.
I receive a long list containing lines with the text:
commit some_long_string_of_hexadecimals
and I need to transform this into:
commit https://github.com/account/repo/commit/some_long_string_of_hexadecimals
The log I am receiving contain n-amount of these logs, so I need the script to do this for all instances of this (some_long_string_of_hexadecimals).
Here are a few example log statements:
commit a98a897a67896a987698a769786a987a6987697a6
Author: Some Person <some#email.com>
Date: Thu Sep 29 09:48:52 2016 +0200
long message describing change.
commit a98a897a67896a987698a769786a987a6987697a6
Author: Some Person <some#email.com>
Date: Thu Sep 29 09:48:52 2016 +0200
more description
I'd like it to look like this:
commit https://github.com/account/repo/commit/a98a897a67896a987698a769786a987a6987697a6
Author: Some Person <some#email.com>
Date: Thu Sep 29 09:48:52 2016 +0200
added handling of running tests from within a docker container
How do I achieve this using a shell command ?
Thanks in advance.
awk '$1 == "commit" {$2 = "https://github.com/account/repo/commit/" $2} 1'
check if field 1 equals "commit"
if so, prepend to field 2
if line matched, print modified line, else print line as is

Using procmail to forward inline

I would like to use procmail to forward a message to another email address. Both the headers and body of the incoming message should be in the body of the outgoing message (inline forwarding).
Example incoming message:
From: outside#example.com
To: me#example.com
Subject: Test
Date: Mon, 03 Nov 2014 05:00:04 GMT
This is a test
The forwarded message should be like this:
From: me#example.com
To: thirdparty#example.com
Subject: Fwd: Test
Date: Mon, 03 Nov 2014 05:01:00 GMT
From: outside#example.com
To: me#example.com
Subject: Test
Date: Mon, 03 Nov 2014 05:00:04 GMT
This is a test
Can this be done using procmail, maybe in conjunction with something like formail?
Easy enough.
:0
* Some conditions, perhaps? Omit this line to forward unconditionally
* ^Subject:[ ]*\/.*
| (echo From: me#example.com; echo To: thirdparty#example.com; \
echo "Subject: Fwd: $MATCH"; echo; cat -) | $SENDMAIL -t
If you don't care about forwarding the original Subject header verbatim, this can be simplified additionally.
The -t flag to sendmail says to use whatever To: and Cc: headers are in the message to determine the recipient. I omitted generating a Date: because (most imitations of) Sendmail will do that for you.
The stuff in the square brackets should be one space and one tab, as usual.
If you want to keep a copy, either add Bcc: yourself (and take care to not have the incoming copy trigger a mail loop!) or change :0 to :0c which makes Procmail continue down the rest if the recipe file.

RegEx match IP on Mail-Header Received:

I try to fiddle a RegEx, which returns me only the Sender IP Address:
http://regexr.com?38atl
This is the RegEx I build, but cant complete:
(?<=\bReceived: from .*\[)(?:\d{1,3}\.){3}\d{1,3}
or
(?<=\bReceived: from )(.*\[)(?:\d{1,3}\.){3}\d{1,3}
So it should only match this (on lines beginning with: Received: from)
127.0.0.1
127.0.0.1
21.22.23.24
And this are a example Mail-Headers i'm search in:
To: a#domain.de
Return-Path: <t#domain.de>
X-Original-To: a#domain.de
Delivered-To: c#domain.tld
Received: from localhost (localhost [127.0.0.1])
by mail1.domain.tld (Postfix) with ESMTP id 3fT3TR72zNz8m8
for <a#domain.de>; Tue, 18 Feb 2014 14:54:35 +0100 (CET)
X-Virus-Scanned: Debian amavisd-new at mail1.domain.tld
X-Spam-Flag: YES
X-Spam-Score: 5.773
X-Spam-Level: *****
X-Spam-Status: Yes, score=5.773 tagged_above=1 required=4.5
tests=[BAYES_05=-0.5, MISSING_MID=0.497, RCVD_IN_PBL=3.335,
RCVD_IN_RP_RNBL=1.31, RDNS_DYNAMIC=0.982, TO_NO_BRKTS_DYNIP=0.139,
T_RCVD_IN_SEMBLACK=0.01] autolearn=no
Received: from mail1.domain.tld ([127.0.0.1])
by localhost (mail1.domain.tld [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id lDJqiZjBn2t4 for <a#domain.de>;
Tue, 18 Feb 2014 14:54:34 +0100 (CET)
Received: from mail.domain.tld (pAAAAAAAA.dip0.t-ipconnect.de [21.22.23.24])
by mail1.domain.tld (Postfix) with SMTP id 3fT3TQ4Nwgz8m5
for <a#domain.de>; Tue, 18 Feb 2014 14:54:34 +0100 (CET)
Date: Tue, 18 Feb 2014 15:02:11 +0100
Sender: "From" <t#domain.de>
From: "From" <t#domain.de>
Subject: Subbbb (192.168.123.123)
Reply-To: t#domain.de
MIME-Version: 1.0
Content-type: text/plain; charset=UTF-8
Message-Id: <3fT3TR72zNz8m8#mail1.domain.tld>
Try this expression:
Received: +from[^\n]*?\[([0-9\.]+)\]
Edit:
For a PHP script try something like this (where $emailHeader contains the data you are searching):
$regex = '/Received: +from[^\\n]*?\\[([0-9\\.]+)\\]/s';
if (preg_match_all($regex, $emailHeader, $matches_out)) {
print_r($matches_out);
} else {
print('Sender IP not found');
}
The <= in the star looks funny, but other than that it seems to be working fine:
(?:\bReceived: from .*\[)((\d{1,3}\.){3}\d{1,3})(?:]\))
I believe what you're looking for is:
(?:\bReceived: from .*?\[)(?<ip>(?:\d{1,3}\.){3}\d{1,3})
the matched IP address will be in capture group named "ip".

Email header showing, dkim=hardfail (test mode) and dkim=permerror (bad sig)

I am trying to write an email client application by c++ and OpenSSL..
When I am checking and sending email through this application then Gmail and Yahoo both are showing wrong in my email header..
Gmail showing > "dkim=hardfail (test mode) header.i=#".
Yahoo showing > "dkim=permerror (bad sig)".
My Email header for Gamil :
Delivered-To: rajforever6#gmail.com
Received: by 10.112.41.134 with SMTP id f6csp80981lbl;
Tue, 26 Mar 2013 02:25:15 -0700 (PDT)
X-Received: by 10.68.59.199 with SMTP id b7mr22705642pbr.167.1364289914515;
Tue, 26 Mar 2013 02:25:14 -0700 (PDT)
Return-Path: <no_feed#korcot.info>
Received: from smtp.korcot.info ([103.18.168.250])
by mx.google.com with SMTP id ak6si16720576pbd.344.2013.03.26.02.25.08;
Tue, 26 Mar 2013 02:25:14 -0700 (PDT)
Received-SPF: softfail (google.com: domain of transitioning no_feed#korcot.info does not designate 103.18.168.250 as permitted sender) client-ip=103.18.168.250;
Authentication-Results: mx.google.com;
spf=softfail (google.com: domain of transitioning no_feed#korcot.info does not designate 103.18.168.250 as permitted sender) smtp.mail=no_feed#korcot.info;
dkim=hardfail (test mode) header.i=#korcot.info
Date: Tue, 26 Mar 2013 02:25:14 -0700 (PDT)
DKIM-Signature: v=1;
a=rsa-sha256;
s=mail;
d=korcot.info;
t=1364289917;
c=relaxed/relaxed;
h=from:to:subject:message-id:mime-version:content-type;
bh=Q3K/t162lFKWTLs4xBY2FR1vT5pThpI6rnqM7i6p/Vo=;
b=Tgrc2nelY/3HA0M14s4RXFvhonXQzFRtDAD/X/0ITvln6JSWjIxgQSX7WOrfAxb4K
kTXV+Bbw6DKK+2aVi2WrCYdduP5wXJpTVnjaCJQTs2+DtAo3sL1re6tz3uHOpa0PmRS
3qRzfXQqN8QczOv63UjAGO6sL+o5atU3vbRYMxg=
From: "Comfirm"<no_feed#korcot.info>
To: "Kuntal"<rajforever6#gmail.com>
Subject: Key6gg6 ?
Message-ID: <20030712040037.46341.5F8J#football.korcot.info>
MIME-Version: 1.0
Content-Type: text/html
My Email header for Yahoo :
From Comfirm Wed Mar 27 02:26:20 2013
X-Apparently-To: raja_kuntal_majumder#yahoo.com via 106.10.150.84; Tue, 26 Mar 2013 11:26:20 -0700
Return-Path: <no_feed#korcot.info>
Received-SPF: softfail (transitioning domain of korcot.info does not design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CCcvQ6CMd.UnOlIt4pFEWwd9Zlo5BIJ4hd9N99qMbul
mGgNYVRBc0f7DokmkLiHSI29k34ifNyh8Z1qbeKWTRo4FXDBa.vfc9cVWqpp
DVF8FbkpuThc7QJ63cszp98TCdZy2Bq5yOMrqEdK85e141MndRChrWmjUplJ
4e_UWqNmaL17cGPzXuJc3TAD3nsdK9qh1ax.9K.jkRwSm4zgWscqosCPAgOJ
lIOo3L3QScOP9iQ6xOfuzm7dxw44Z3WBHMthoOgw_MGt488EClyDr2PiJT.f
1_BklnxGS2iuYH2TLyY69ESKE0Y4pPGmaboLASqBQkQZ6xaoFM8HDoIB20zK
KrNadXnlkMW.t6RuIcaPX3fOrKzvnKPerZ3NA1kn
X-Originating-IP: [103.18.168.135]
Authentication-Results: mta1360.mail.bf1.yahoo.com from=korcot.info; domainkeys=neutral (no sig); from=korcot.info; dkim=permerror (bad sig)
Received: from 127.0.0.1 (HELO smtp.korcot.info) (103.18.168.135)
by mta1360.mail.bf1.yahoo.com with SMTP; Tue, 26 Mar 2013 11:26:19 -0700
DKIM-Signature: v=1;
a=rsa-sha256;
s=mail;
d=korcot.info;
t=1364322363;
c=relaxed/simple;
h=from:to:subject:mime-version:content-type;
bh=Q3K/t162lFKWTLs4xBY2FR1vT5pThpI6rnqM7i6p/Vo=;
b=THj4wE+EOSKThXGIUPBgcTlWTICIDFikgEvlQVpBotViQTNW+k/dpr58kVZ1HAght
KTdACtbEO2m3A17vxrY1kEQazhwu7pbWIW5TwBfUtIU9SbFBL88AQz2fxxi6BHqEfNh
WYeGG0mEskG9J2JFeNVG0WaaNJ9gTh5t/4nqvVc=
From: "Comfirm" <no_feed#korcot.info>
To: "Kuntal" <raja_kuntal_majumder#yahoo.com>
Subject: Key6gg6 ?
MIME-Version: 1.0
Content-Type: text/html
Content-Length: 287
My TXT records in DNS(godaddy.com) :
# >>>> v=spf1 a mx mx:smtp.korcot.info ip4:103.18.168.250 ~all
mail._domainkey >>>> k=rsa; t=y; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCjKsxH3Hb8UrNZ+Aar7GfJ30dcbS19i+89JA8SSlDEhsFfTAR9UZIolxKtD3HgPzhWGfcoLkQg28NS/Y3tT/WTvfXxryDyFRIbKJox6VbVmmvSmATsik1l2YQSkTTpeHX6nzxgzRwDVvmLfZBZBbO3n+y0YNTucOUsfNFYCL/UAwIDAQAB
_domainkey >>>> t=y; o=~;
Really I don't have knowledge why Gmail and Yahoo showing "dkim=hardfail (test mode) header.i=#" and "dkim=permerror (bad sig)", both header should be "dkim=pass (ok)"..
So please give me advice.
Please tell me what should I do to solve this problem..
Thanks...
You didn't mention whether you are using a standard library to calculate the DKIM signature, or have done your own. I strongly recommend OpenDKIM as a good library to use if you aren't already.
Another place to test is to send a message to the mail reflector at sa-test#sendmail.net. It may give you more diagnostic information.
You should check the header fields that are signed (From, To, Subject, Mime-Version, and Content-Type) between what you sent originally and what was received. Some mailers "helpfully" rewrite these header fields, breaking the signature in the process. For example, it could have signed no_feed#smtp.korcot.info and subsequently changed it to no_feed#korcot.info.

Detecting characters in C++ char stream

I am working on a piece of arduino code that is using the BlackWidow version with wifi built in. Using the WiServer.h library, I'm using the SimpleClient.pde example with mods to send a call to a webserver that will simply return an integer - 0, 1, or 2. The end goal is to turn on a pin for the proper red, green, or yellow of a stoplight. The integers represent the aggregate state of our Hudson CI.
I'm a PHP lazy bastard, and pointers scare me. The code I am working with is
// Function that prints data from the server
void printData(char* data, int len) {
// Print the data returned by the server
// Note that the data is not null-terminated, may be broken up into smaller packets, and
// includes the HTTP header.
while (len-- > 0) {
Serial.print(*(data++));
}
}
printData() is the callback of the call to the webserver, and when run it sends the following to the serial monitor (this is 3 loops, no newline before new output):
HTTP/1.1 200 OK
Date: Thu, 10 Feb 2011 17:37:37 GMT
Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8k DAV/2 PHP/5.2.11
X-Powered-By: PHP/5.2.11
Content-Length: 1
Connection: close
Content-Type: text/html
0HTTP/1.1 200 OK
Date: Thu, 10 Feb 2011 17:37:45 GMT
Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8k DAV/2 PHP/5.2.11
X-Powered-By: PHP/5.2.11
Content-Length: 1
Connection: close
Content-Type: text/html
0HTTP/1.1 200 OK
Date: Thu, 10 Feb 2011 17:37:58 GMT
Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8k DAV/2 PHP/5.2.11
X-Powered-By: PHP/5.2.11
Content-Length: 1
Connection: close
Content-Type: text/html
0
The part that I need to identify is the 0, which could also be 1 or 2.
Instead of printData(), this function will become turnOnAppropriateLight() or something, by simply setting a pin to HIGH. This will then activate a relay, to power the corresponding LED array.
Now that I've written this up it looks like I just need to keep the last character around and do a switch based on the value. The *(data++) is the confusing part even though I know it's incrementing a pointer index...I'm just not sure how to go directly to the last char in that index. No need for this looping to spit out the result.
This is not robust AT ALL, but
Serial.print(data[len-1])
See what that gets you
this should be all you need:
data[len - 1]
You could be neurotic and parse each line, or look for the last tags: Content-Type:.
I would convert the C-style string into a C++ std::string then use the find_first method to look for the keywords.
The std::istringstream can be used to convert from text "0" to numeric 0.