4

Is there anyway to set up a filter that will create and apply a new label for every word in the subject line? Something like label:{subject} maybe?

Obviously I wouldn't be using this for standard gmail use, I'm trying to setup gmail as a kind of note taking repository and would love to be able to just enter tags in the subject and have them automatically turned into labels.

5 Answers 5

2

You can do what are you asking but it takes a bit of coding in JavaScript (https://developers.google.com/apps-script/).

You have to create a filter to apply a label "_toBeParsed" (or named as you pleased) to every incoming email.

The Google Apps Script should periodically search for each thread with that label, parse the subject and programmatically create a label for each word, then it must remove the original label.

Mind that in Gmail you can have a finite number of labels so you should avoid the creation of labels for common and short words.

2

In your script, get the subject line of the email. Then split that text into an array. Then create labels for each word in that array.

Here is a great script that I've used to create nested labels: https://ctrlq.org/code/19895-create-nested-gmail-labels

I've found using this method to create labels cuts down a LOT on the label clutter.

If you are still looking for scripts to get started, I can share code that I have cobbled together for similar operations -- but fair warning -- it's not pretty and I don't EVER claim to be an experienced coder, so my methods are probably not the best!

1

I've never run across a way to create labels like you asked, but you can use gmail's search to do the same thing. For example, you can search for:

subject:Monkeys

Which will return all emails with Monkeys in the subject. You can also set up bookmarks for common searches.

1
  • True. I could use greasemonky to setup some persistant searches to take the place of tags/labels, but I'd rather find a way to make the labels. Thanks for the input.
    – matt
    Nov 8, 2010 at 18:55
1

You could use the Gmail Labs Quick Links feature to create links to custom searches.

E.g. You could search for subject:Monkeys, then add a quick link to the page displaying the search result. After that you could display the search results for your chosen keywords with one click.

I know these are not labels but look very similar in the GUI and you would not need to use greasemonkey.

2
  • 1
    How does this help me get any closer to what I'm trying to do? I want labels (or Custom Search links) to be created dynamically based on the words in the subject line of an email. So if I sent myself an email with the subject line "Monkeys" it would then create a label "Monkeys". It does not help me to have to predefine a label or a custom search because I want those links to be built based on the content of messages.
    – matt
    Feb 12, 2011 at 23:18
  • Sorry. I wasn't avear that the dynamic part is such an important criteria. In that case I think your only option is greasemonkey. Depending on your use-case you might be better of with a fixed set of labels to avoid a proliferation of tags (due to typos, tags only used once, etc.)
    – Andris
    Feb 13, 2011 at 10:40
1

Here you have a code for the Google Apps Script which iterates through emails and for each word in the all emails subjects create a new tag.

To make it fully work you need to just add the label for each thread which is processed.

here you fan find this code and additional functions which could help.

To invoke code open new Google Apps Script window

enter image description here

It is possible to create time triggers for invoking functions.

function createTagsFromSubject() {
var threads=GmailApp.getInboxThreads();
for(var i=0;i<threads.length;i++){
  var subject=threads[i].getMessages()[0].getSubject()
  Logger.log(subject)
  createLabels(subject)
  }
}

function createLabels(subject)
{
  createLabelSafe("AutoContainer");
  var words=subject.split(" ");
  for(var i=0;i<words.length;i++)
  {
   // Logger.log(words[i]);
    createLabel(words[i])
  }
}

function createLabel(word)
{
  word=word.replace("/","").replace("|","").replace(":","").replace("\"","").replace("(","").replace(")","")
  if (word!=null && word!="")
  {
  var finalLabel="AutoContainer/"+word;
  createLabelSafe(finalLabel)
  }
}

function createLabelSafe(word)
{
  Logger.log(word);
  if (word=="/") return
  if (word==" ") return
  
  var label=GmailApp.getUserLabelByName(word)
  if (label==null)
  {
    GmailApp.createLabel(word)
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.