-
-
Save jaysonjphillips/1b33163a9a4e9713de33193198594c21 to your computer and use it in GitHub Desktop.
Google Apps Script: Send converted documents from Gmail to Evernote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* reMarkable Text to Evernote | |
*/ | |
const EMAIL_ADDRESS = 'email+notes@gmail.com'; | |
const EVERNOTE_ADDRESS = "email-address@m.evernote.com" | |
const REMARKABLE_LABEL = GmailApp.getUserLabelByName('remarkable-stored') | |
// regex for parsing | |
const NOTEBOOK_REGEX = /(\[@[a-zA-Z0-9 ]+\])+/g; | |
const TAGS_REGEX = /(#[ a-zA-Z0-9,.:;-]+)+/g; | |
const TITLE_REGEX = /(=[a-zA-Z0-9,. ]+)+/g; | |
const REMINDER_REGEX = /(\+[a-zA-Z0-9 \-\/]+)+/g; | |
function PushToEvernote(){ | |
const BASE_QUERY = `in:inbox to:${EMAIL_ALIAS} is:unread`; | |
const results = GmailApp.search(BASE_QUERY); | |
results.map( thread => { | |
const message = thread.getMessages()[0] | |
// get content of note from the body | |
const content = message.getPlainBody() | |
// parse the notebook, title, tags, and reminders | |
const notebookResult = content.match(NOTEBOOK_REGEX) | |
const titleResult = content.match(TITLE_REGEX) | |
const tagsResult = content.match(TAGS_REGEX) | |
const reminderResult = content.match(REMINDER_REGEX) | |
// filter out symbols from notebook name | |
const name = notebookResult && notebookResult[0].replaceAll(/([\[\] ]+)+/g, "").toLowerCase() || "" | |
// filter out symbols from title | |
const title = titleResult && titleResult[0].replaceAll(/(=[\[\] ]+)+/g, "") || "" | |
// filter out spaces between word and # if any, join multiple as space delimited | |
const tags = tagsResult && tagsResult.map(tag => tag.replace(/(#[ ])\w+/, "").toLowerCase()).join(" ") || "" | |
// filter reminder and swap + for ! | |
const reminder = reminderResult && reminderResult[0].replace("+", "!").replace(" ", "").toLowerCase() || "" | |
// set up evernote structured subject line | |
const subject = `${title} ${reminder} ${name} ${tags} +` | |
MailApp.sendEmail(EVERNOTE_ADDRESS, subject, content) | |
message.markRead() | |
thread.addLabel(REMARKABLE_LABEL) | |
thread.moveToArchive() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment