Self-Archiving Emails

The concept of Inbox Zero has been around since 2007, and we can thank Merlin Mann for popularizing it. If you have not watched the presentation, I highly recommend doing it, because it is still relevant in 2025.

For the past 3 years, I have been running an automation which I now consider essential to keeping my inbox tidy. I call it self-archiving emails. The concept is simple: if an email has been sitting in my inbox for long enough (and for me, that's currently 8 months), I will probably never do anything about it. So it might as well archive itself. In practice, 8 months is a worst-case scenario, because a lot of the emails I receive are only interesting for a few days. The expiration date is set on a case by case situation, using regular email rules.

Gmail implementation

I am leveraging labels to implement this strategy. My flow is as follows: using basic filters, I label every incoming email with one of the following: archive-1d, archive-3d, archive-7d, archive-1m, archive-2m, archive-4m or archive-ifread. Every hour, a script archives every message which sits in my inbox and is older than what the label indicates.

The script runs as a google apps script:

function run() {
  // find all the archive-xx labels
  const labels = GmailApp.getUserLabels()
    .map(label => label.getName())
    .filter(name => name.startsWith("archive-") && name.length == "archive-xx".length);

  // archive all the expired emails according to their respective labels
  for (const label of labels) {
    const duration = label.split("-")[1];
    archive("in:inbox label:" + label + " older_than:" + duration)
  }

  // archive anything older than 8m
  archive("in:inbox older_than:8m");

  // archive emails which have no value once I have seen them
  archive("in:inbox is:read label:archive-ifread");
}

function archive(search) {
  Logger.log("archiving: " + search)

  const threads = GmailApp.search(search);

  Logger.log("found " + threads.length + " threads:");
  for(var i = 0; i < threads.length; i++) {
   const thread = threads[i];
   Logger.log((i+1) + ". " + thread.getFirstMessageSubject());
  }

  const batch_size = 100;
  while (threads.length) {
    const this_batch_size = Math.min(threads.length, batch_size);
    const this_batch = threads.splice(0, this_batch_size);
    GmailApp.moveThreadsToArchive(this_batch);
  }
}

There are already plenty of google apps scripts tutorials, so I will not go into the details of deploying this script, but it roughly involves going to script.google.com, pasting this code into a new project and setting the function run to trigger every hour. I am sure you will figure this out.

Office 365

My workplace uses office 365, but that did not stop me from implementing the same logic using MS powerflows. It is, however, massively ugly, so I will not share it here. If you are interested in how to do it, send me an email, I may post another article about it if this is a popular request.

Feedback

3 years later, I can report that this concept of self-archiving emails has drastically reduced the size of my inbox, to the point that I could not imagine living without it. Surprisingly, I am the only person I know who runs such an automation. I discussed about it with some friends the other day, and because this generated some interest, I decided to share it here. If you end up using it as well, feel free to shoot me an email, and if you promote this approach to others, please credit me 😉

To the comments

All posts

  1. Scripting sudo with pass
  2. Looping simultaneously over multiple lists in legacy shells
  3. SSH over SSL, episode 4: a HAproxy based configuration
  4. Editing a CV in markdown with pandoc
  5. Using openid and the likes to protect static content (lighttpd)
  6. Git on lighttpd
  7. Sigal, a static gallery generator
  8. Jabber notifications on ssh login
  9. Choose your passphrase with a die
  10. Operations Research and Beer drinking
  11. Releasing Michel, a flat-text-file-to-google-tasks uploader
  12. Going static
  13. plowbot, a jabber bot that downloads links from 1-click hosters
  14. SSH over SSL, episode 3: Avoiding using a patched apache.
  15. [Je préfÚre ton clone] padopi
  16. Using a shell version of supergenpass from vimperator/pentadactyl
  17. Saving your crontab in your dotfiles
  18. Notifications from google calendar on my desktop
  19. SSH over SSL, episode 2: replacing proxytunnel with socat
  20. SSH over SSL, a quick and minimal config.
  21. Vim: complete C++ accurately, pulling informations from the compiler, with gccsense and clang_complete
  22. Google releasing a constraint programming library
  23. Mise Ă  jour de TalkMyPhone
  24. TalkMyPhone, une appli android pour recevoir des notifications de son téléphone
  25. De l'intĂ©rĂȘt de dĂ©tacher des programmes de la console (sans screen)
  26. renaming files and variables from vim
  27. Continuous background compilation within vim
  28. Utilisons incron pour ĂȘtre notifiĂ©s des Ă©vĂ©nements du systĂšme de fichiers
  29. La TODO liste du pauvre
  30. Gérer ses plugins vim avec :GetLatestVimScripts
  31. gdb 7.0 est sorti, c'est une merveille et vous ne le saviez pas.
  32. autotools, doxygen, et génération conditionnelle
  33. Mettre des couleurs un peu partout (gcc, diff, grep...)
  34. vim+gdb=vimgdb
  35. l'UML automatisé et le libre : c'est pas gagné!
  36. Les lecteurs de flux rss, en ligne, indépendants, libres (suite).
  37. Les lecteurs de flux rss en ligne libres
  38. Couper une vidéo et extraire une scÚne d'un film
  39. Faire un gif animé à partir d'un film

Atom feed