gmail-processor
gmail-processor copied to clipboard
Proposal: A better way to specify storage locations
To get more flexibility for the future it is necessary to redo the filename substitution logic. Therefore I'd like to get some feedback on the draft below:
Example configuration (DRAFT):
{
"filter": "has:attachment from:[email protected]",
"match": {
"from": "(.+)@example.com",
"subject": "Prefix - (.*) - Suffix",
"to": "my\.address\+(.+)@gmail.com" // Support for [email protected] syntax for Gmail addresses
}
"attachments": [
{
"match": {"name": "Image-([0-9]+)\.jpg"},
"location": "Folder1/Subfolder1/${match.subject.1}/${email.subject} - ${match.att.1}.jpg",
// example: subject="Prefix - Test - Suffix", filename="Image-3.jpg" =>
// location="Folder1/Subfolder1/Test/Prefix - Test - Suffix - 3.jpg
"overwrite": true // Overwrite existing files
},
{
"match": {"name": ".+\..+"}, // means *.* or <att.basename>.<att.ext>
"location": "Folder2/Subfolder2/${att.basename}-${date:yyyy-MM-dd}.${att.ext}",
// example: subject="Prefix - Test - Suffix", filename="file.txt" =>
// location="Folder2/Subfolder2/Test/Prefix - Test - Suffix - 3.jpg
"overwrite": false // Skip existing files
}
],
},
Substitution parameters (DRAFT):
- Threads (see https://developers.google.com/apps-script/reference/gmail/gmail-thread for available data)
- ${thread.subject}: Subject of first message in thread
- ${thread.id}: Thread ID
- ${thread.labels}: Thread labels
- ${thread.lastMessageDate:<SimpleDateFormat>}: Date of last message in thread
- Emails (see https://developers.google.com/apps-script/reference/gmail/gmail-message for available data):
- ${message.date:<SimpleDateFormat>}: Date and time
- e.g.
${date:yyyy-MM-dd_HH-mm-ss} - For all supported format letters see https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
- e.g.
- ${message.from}: Sender email address
- ${message.from.match.[1-9]}: Regex match in sender email address
- ${message.id}: Email ID
- ${message.subject}: Email subject
- ${message.subject.match.[1-9]}: Match in email subject
- ${message.to}: Recipient email address (NOTE: May contain more email addresses!)
- ${message.to.match.[1-9]}: Match in recipient email address
- ${message.date:<SimpleDateFormat>}: Date and time
- Attachments (see https://developers.google.com/apps-script/reference/gmail/gmail-attachment for available data):
- ${attachment.contentType}: Attachment content type (e.g. application/jpeg)
- ${attachment.contentType.match.[1-9]}: Attachment content type (e.g. application/jpeg)
- ${attachment.index}: Attachment index (starting from 0)
- ${attachment.name}: Attachment filename
- ${attachment.name.base}: Attachment file basename without extension
- ${attachment.name.ext}: Attachment file extension
- ${attachment.name.match.[1-9]}: Matching attachment filename string
- Regular expression matches (*.match.[1-9]):
- The parenthesis "()" define the possible match group number, counted from left to right.
- For more information about using regular expressions see https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/RegExp
Let me know, what you think so I can start implementing the feature.
Does this work? simply put, I'd like to make a new folder based on the email subject and senders name everytime attachments are sent in an email. i can't understand the above logic.
i'd also like for it to save the email as a pdf, and attachments in the same folder.
the use case is someone sending me a product email with attachments, and i'd like to save it according to the product type and the sender.
I'm closing this issue since GMail2GDrive is discontinued and has been superseded by the much improved Gmail Processor. It fully implements this functionality in modified and improved form. See the Getting Started Guide as well as the Reference Docs for more information