<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><generator uri="https://gohugo.io/" version="0.156.0">Hugo</generator><title type="html">Gmail Notes on Marcin Jasion - Pragmatic DevOps</title><link href="https://2a300508.mjasion.pages.dev/notes/gmail/" rel="alternate" type="text/html" title="html"/><link href="https://2a300508.mjasion.pages.dev/notes/gmail/index.xml" rel="alternate" type="application/rss+xml" title="rss"/><updated>2022-09-13T08:00:00+00:00</updated><id>https://2a300508.mjasion.pages.dev/notes/gmail/</id><entry><title type="html">Cleanup Gmail messages by filter</title><link href="https://2a300508.mjasion.pages.dev/notes/gmail/cleanup/?utm_source=atom_feed" rel="alternate" type="text/html"/><id>https://2a300508.mjasion.pages.dev/notes/gmail/cleanup/</id><published>2022-09-13T08:00:00+00:00</published><updated>2022-09-13T08:00:00+00:00</updated><content type="html"><![CDATA[<!-- Variable -->
<div class="note-card ">
    <div class="item">
        <h5 class="note-title"><span>Cleanup Gmail emails by filter</span></h5>
        
            <div class="card">
                <div class="card-body"><p>This is example how to remove Github Notifications of failed jobs after 7 days:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-javascript" data-lang="javascript"><span style="display:flex;"><span><span style="color:#66d9ef">function</span> <span style="color:#a6e22e">cleanupByFilter</span>() {
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">deleteEmails</span>(<span style="color:#e6db74">&#39;from:notifications@github.com older_than:7d subject: &#34;Run failed&#34;&#39;</span>)
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// For more filters add more `deleteEmails` function executions here
</span></span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">function</span> <span style="color:#a6e22e">deleteEmails</span>(<span style="color:#a6e22e">filter</span>) {
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">var</span> <span style="color:#a6e22e">threads</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">GmailApp</span>.<span style="color:#a6e22e">search</span>(<span style="color:#a6e22e">filter</span>);
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">Logger</span>.<span style="color:#a6e22e">log</span>(<span style="color:#e6db74">&#34;Deleting &#34;</span> <span style="color:#f92672">+</span> <span style="color:#a6e22e">threads</span>.<span style="color:#a6e22e">length</span> <span style="color:#f92672">+</span> <span style="color:#e6db74">&#34; messages from filter: &#34;</span> <span style="color:#f92672">+</span> <span style="color:#a6e22e">filter</span>)
</span></span><span style="display:flex;"><span>   <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">var</span> <span style="color:#a6e22e">i</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; <span style="color:#a6e22e">i</span> <span style="color:#f92672">&lt;</span> <span style="color:#a6e22e">threads</span>.<span style="color:#a6e22e">length</span>; <span style="color:#a6e22e">i</span><span style="color:#f92672">++</span>) {
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">var</span> <span style="color:#a6e22e">messages</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">threads</span>[<span style="color:#a6e22e">i</span>].<span style="color:#a6e22e">getMessages</span>();
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">var</span> <span style="color:#a6e22e">j</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; <span style="color:#a6e22e">j</span> <span style="color:#f92672">&lt;</span> <span style="color:#a6e22e">messages</span>.<span style="color:#a6e22e">length</span>; <span style="color:#a6e22e">j</span><span style="color:#f92672">++</span>) {
</span></span><span style="display:flex;"><span>         <span style="color:#66d9ef">var</span> <span style="color:#a6e22e">message</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">messages</span>[<span style="color:#a6e22e">j</span>];
</span></span><span style="display:flex;"><span>         <span style="color:#a6e22e">message</span>.<span style="color:#a6e22e">markRead</span>()
</span></span><span style="display:flex;"><span>         <span style="color:#a6e22e">message</span>.<span style="color:#a6e22e">moveToTrash</span>()
</span></span><span style="display:flex;"><span>      }
</span></span><span style="display:flex;"><span>   }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>To set this up see my post <a href="/posts/development/label-gitlab-notifications/">here</a>.</p>
</div>
            </div>
        
    </div>
</div>

]]></content></entry></feed>