gmail-processor icon indicating copy to clipboard operation
gmail-processor copied to clipboard

Use subject substring for attachment filename

Open ahochsteger opened this issue 8 years ago • 8 comments

Usage example (by @CgKortz):

  • Attachment original name is: Image-1.jpg
  • Subject of email is: UDisc iOS Scorecard - McClain Park (Default Layout - 05-28-2016 08:35 AM)

I would like the attachment to be renamed: McClain Park 05-28-2016 08:35 AM I would think removing the (Default Layout - might be harder but to remove the UDisc iOS Scorecard - should be easy like remove the first 22 characters of the subject before the rename. I googled some and I could not find anything but I also have never scripted so ..... any help would be greatly appreciated.

ahochsteger avatar Jun 05 '16 14:06 ahochsteger

@CgKortz, I guess something like this would be flexible enough to satisfy your requirements:

{ // Replace all files with the variable 'filenameTo' string using regex match groups from subjectRegex.
    "filter": "(from:[email protected] OR from:[email protected])",
    "folder": "Examples/example3ab",
    "subjectRegex": "UDisc iOS Scorecard - ([^())]+) \(.* - ([APM0-9: -]{19})\)", // Provides the matching regex groups as $1, $2, ... for substitution in filenameTo
    "filenameFrom": "Image-1.jpg",
    "filenameTo": "'$1$2''",
    "archive": true
}

Please tell me, if that's what you were looking for. I'd try to implement it since it would indeed make it much more flexible to use!

ahochsteger avatar Jun 05 '16 14:06 ahochsteger

That looks like what I am looking for.

CgKortz avatar Jun 05 '16 14:06 CgKortz

@CgKortz, may you try, if the file Code.gs.txt does what you expect?

I've tested it with the following configuration (please adjust to your usage):

{ // Replace all files with the variable 'filenameTo' string using regex match groups from subjectRegex.
    "filter": "from:[email protected]", 
    "folder": "Test-Folder", 
    "subjectRegex": "Prefix - (.*) - Suffix", // Provides the matching regex groups as $1, $2, ... for substitution in filenameTo
    "filenameFrom": "testfile.txt", 
    "filenameTo": "'$1 'yyyy-MM-dd",
    "archive": true 
},

The test email had the subject Prefix - Test E-Mail 1 - Suffix and an attachment with the filename testfile.txt.

Please tell me, if this works for you so I can integrate that change.

ahochsteger avatar Jun 06 '16 21:06 ahochsteger

This dose not seem to work. I have tried with my own Regex and I used your example as well. I just get the attachment as the original attachment name.

CgKortz avatar Jun 07 '16 13:06 CgKortz

Log File 16-06-07 13:49:12:407 CDT] INFO: Starting mail attachment processing. [16-06-07 13:49:12:530 CDT] INFO: Processing rule: subject:UDisc iOS Scorecard -label:processed newer_than:1m [16-06-07 13:49:12:531 CDT] INFO: Processing thread: UDisc iOS Scorecard - Prince Solms (Default Layout - 06-07-2016 11:14 AM) (runtime: 0.125s/280s) [16-06-07 13:49:12:657 CDT] INFO: Processing message: UDisc iOS Scorecard - Prince Solms (Default Layout - 06-07-2016 11:14 AM) (1552bcc0c8726ae5) [16-06-07 13:49:12:659 CDT] INFO: Processing attachment: Image-1.jpg [16-06-07 13:49:14:624 CDT] INFO: constructNewFilename('UDisc iOS Scorecard - ([^())]+) (.* - ([APM0-9: -]{19}))', ''$1$2''') [16-06-07 13:49:14:625 CDT] Exception: Invalid argument: 'Prince Solms(Default Layout - 06-07-2016 11:14 AM'')

CgKortz avatar Jun 07 '16 18:06 CgKortz

Is there any chance to overwrite current file ? For example - i receive stock info everyday with file named "Company stock 24-05-2017.xls". i created rule for renaming it to stock.xls, but every day i have new duplicates with same name.

fairyfeller avatar May 24 '17 13:05 fairyfeller

Thank you so much for this project. Your work is greatly appreciated. Has any progress been made to rename the file uploaded to Google Drive as the subject line? I would also like to place the file in a folder that is named by the content of the message body. I am using this with a form in Acrobat. The user submits the form and the subject line and body of the email is generated based off of form content. The form is submitted by email to a gmail account. Any help would be very much appreciated as I am pretty new to scripting.
I should also note that the filename of the form that is emailed might vary, but this gmail address is set up to only receive these forms. Basically, i want to save EVERY attachment sent to this email address in a folder named as the body of the email (example "xxxx-xxxx") and as the file name the same as the subject line of the email. Thanks.

MikeL63 avatar May 25 '17 14:05 MikeL63

I've move the proposal to a separate issue, please comment here: https://github.com/ahochsteger/gmail2gdrive/issues/28

ahochsteger avatar Apr 28 '19 18:04 ahochsteger

I'm closing this issue since GMail2GDrive is discontinued and has been superseded by the much improved Gmail Processor. It provides the functionality mentioned above. See the Getting Started Guide as well as the Reference Docs for more information

ahochsteger avatar Sep 20 '23 20:09 ahochsteger