I already posted this on Stack Overflow
I have emails which have following in email body:
1 email:
Event demon log entry:
***
2.email:
Event demon log entry:
***
3 email:
Event demon log entry:
***
These emails have attachments which also have job names, i want to get job name for every email once
Email body for 2nd email
The difference is in line break in 1st email body
Current output
as you can see, i'm getting duplicate jobs and missing job name from 1st email
Desired output
tried
['eggs***\r', 'eggs***']
['eggs***\r', 'eggs***']
['\r']
I have emails which have following in email body:
1 email:
Event demon log entry:
***
2.email:
Event demon log entry:
***
3 email:
Event demon log entry:
***
These emails have attachments which also have job names, i want to get job name for every email once
for emailid in items: resp, data = conn.uid("fetch",emailid, "(RFC822)") if resp == 'OK': email_body = data[0][1].decode('utf-8') mail = email.message_from_string(email_body) #get all emails with words "PA1" or "PA2" in subject if mail["Subject"].find("PA1") > 0 or mail["Subject"].find("PA2") > 0: #search email body for machine name (string after word "MACHINE") regex1 = r'(?<!^)MACHINE:\s*(\S+)' a=re.findall(regex1 ,email_body) print (c)example of message body from 1st email for MACHINE section:
Quote:MACHINE: =^M
ld***
Email body for 2nd email
Quote:MACHINE: eggs***^M
MACHINE: eggs***<br>^M
The difference is in line break in 1st email body
Current output
Quote:['eggs***', 'eggs***<br>']
['eggs***', 'eggs2***<br>']
['=', '=']
as you can see, i'm getting duplicate jobs and missing job name from 1st email
Desired output
Quote:['eggs***']
['eggs***']
['ld***]
tried
regex2 = r'\bMACHINE:\s*(?:=.*)?\s*([^<^\n ]+)'but got
['eggs***\r', 'eggs***']
['eggs***\r', 'eggs***']
['\r']