Hello , I am trying to write a script which can parse email header and based on certain criteria/parameter it will update the email subject detail in the database.
I have written a code but it is taking too much time to execute the code and each process is utilizing 100% of its cpu resources allocated to the process. The code itself is too big so I can not paste it here since there are lots operation being performed on the email header after fetching the correct emails. However I am pasting the search string which I am using and I think it is only bugy. search_string => '(.*)(From:)(\s*)(.*)(\s*)(\...@*\s*)(\s*)(\S*\s*\S*\s*\S*\s*\S*\s*\S*)(s*)(.*)(\s*)(id)(\s*)(\w\w\w\w\w\w-\w\w\w\w\w\w-\w\w*)(\s*)(.*)(\s*)(for \...@\s*)(\s*)(;)(\s*)(\S*\s*\S*\s*\S*\s*\S*)(\s*)(\d\d:\d\d:\d\d)(.*)(\s*)(Subject:)(\s*)(.*)(\s*)[(Primary Hostname)](\s*)(.*)', I want to gather particular field from the email header along with the complete message. The field which I want to select from the email header are 1 From address (Filed number 6) 2 For address (Since mails being forwarded to my email address from else where) (Filed number 17) 3 Date and Time (Filed number 22 and 24) 4 Message ID (Filed number 14) 5 Complete Subject Line (Filed number 29) 6 Complete Body (Filed number 33) Above gives me the output but it takes too much time sometimes it takes 30 min if multiple mail comes to email address since I am writing these details in a file at the moment but I am worried because I want to update all these details to my database. Is there any way around to sort this out and it should not take more than a sec to complete the task. I know the above search string is not perfect and it fails if mail header format is different . If someone can shed some light on this. I have very less experience in perl programming so if you want to ask any thing please ask me and if some could come over chat then it will be really appreciated. Thank you Pratap