Pages: 1
RSS
Extract attachments by filter using RegEx on subject, Extract a string from email subject using RegEx and then use the result to create a folder for saving
 
I am trying to create a filter that extracts a string from the email subject using RegEx and then uses the result to create a folder for saving.

More specifically, I want to extract the client's PO number from the email subject and create a folder like this:

c:\....\[client name]\[message date].[PO number]\


I already know how to do it using the message text:


Set up a filter with "Action" "Extract attachments", then setting the folder ("Extract attachments to (template)") to:

c:....\%FilterName\%ODATESHORT.%REGEXPTEXT="\d+"

wh ere
1) %FilterName corresponds my client's name.
2) %ODATESHORT is the message's date.
3) %REGEXPTEXT="\d+" matches the first number of the message [assuming this is the PO number]

I have tested this and it works.


Alas, some clients put PO number only in the email subject.

As there is no single macro for using RegEx directly on the subject line (comparable to %REGEXPTEXT), I think I should combine these two macros:

%REGEXPMATCH="%OSUBJ"
%SETPATTREGEXP="\d+"

My problem is, I don't know how to combine these two in the filter action dialogue. This doesn't seem to allow processing multiple commands, i.e. first running %REGEXPMATCH="%OSUBJ" and then %SETPATTREGEXP="\d+".

Maybe there is a special syntax for that? Is this possible at all?
 
Quote
Ulrich Leininger wrote:
Set up a filter with "Action" "Extract attachments", then setting the folder ("Extract attachments to (template)") to:

c:....\%FilterName\%ODATESHORT.%REGEXPTEXT="\d+"

I can't help you with the question about combining two commands --sorry--, but when you are creating folder names, it may be wise to use the %VALIDFILECHARS macro, so as to make sure that you'll get a valid folder name.

Edited to add:

Oh wait, you're doing this in the dialog of the Extract Attachments action. Maybe The Bat will validate the address there automatically.

However, are you sure that this is the action that you want to use -- do you actually have to export any attachments? If, instead, you would use an action that generates a new message, you could use many more macro commands in the template of that message. Maybe that would give you some more flexibility here?
I volunteer as a moderator to help keep the forum tidy. I do not work for Ritlabs SRL.
 
Thanks for your reply. I am not sure whether the folder name is validated automatically, but concerning %VALIDFILECHARS, I have the same problem I described above.

To maybe put my question more simply, I don't know how to combine any macros in the filter action dialogue. I can use single macros that return a string, but I don't know how to perform any kind of "programming", i.e. performing several steps in a sequence.

In message templates, you can simply write multiple lines of code, I assume. But the filter action dialogue allows only a single line.


(I don't want to create a new message, but save incoming attachments automatically in an automatically created folder. This would be incredibly useful for my project management.)
Edited: Ulrich Leininger - 01 May 2020 21:46:35
 
Quote
Daniel van Rooijen wrote:

However, are you sure that this is the action that you want to use -- do you actually have to export any attachments? If, instead, you would use an action that generates a new message, you could use many more macro commands in the template of that message. Maybe that would give you some more flexibility here?

I confirmed that these two lines work fine if put in a message template:

%SETPATTREGEXP="\d+"
%REGEXPMATCH="%OSUBJ"

That is, they return the first number in the subject line.


I want to do the same in a filter action, but don't know how since cannot write multiple lines.

I tried using the "Set User Param" filter action to set %SETPATTREGEXP to "\d+", but this doesn't seem to work either.
 
Ok, I solved it myself!

This works:

C:\.....\%FilterName\%ODATESHORT.%SETPATTREGEXP="\d+"%REGEXPMATCH="%OSUBJ"

So basically you can just write both lines in a single line without any separator. Simple enough, in hindsight.

I love this software.
 
Cool! Glad to hear that you've got it to work!
I volunteer as a moderator to help keep the forum tidy. I do not work for Ritlabs SRL.
Pages: 1