{"id":213,"date":"1997-09-09T01:36:29","date_gmt":"1997-09-09T09:36:29","guid":{"rendered":"http:\/\/www.birdhouse.org\/betips\/?p=213"},"modified":"1997-09-09T01:36:29","modified_gmt":"1997-09-09T09:36:29","slug":"bemail-building-filters","status":"publish","type":"post","link":"https:\/\/www.betips.net\/?p=213","title":{"rendered":"BeMail: Building filters"},"content":{"rendered":"<p>Have you ever wanted to filter your BeMail into a given folder after downloading?<\/p>\n<p>Although Be&#8217;s built-in Find function is powerful and can be run from the command line (see <a href=\"\/chunga.php?ID=176\">Queries from Terminal<\/a>), the problem with querying BeMail is that you can&#8217;t query all the attibutes you might like (e.g., &amp;quot;CC:&amp;quot;).<br \/>\nThe following BASH script queries for my new mail and then greps it for a search word, in this case, &amp;quot;beusertalk.&amp;quot; Then it moves the results to a target folder, in this example, into the &amp;quot;New&amp;quot; folder (\/boot\/home\/mail\/BeUserTalk\/New\/). Although it is far from being fool-proof, it more or less gets the job done.<br \/>\nThe second problem I ran into was automating the process, so that the filter ran when I got new mail. After a number of unsatisfactory attempts, I finally decided to on the following solution.<br \/>\nI named this script &amp;quot;mailbox&amp;quot; and placed it in my &amp;quot;mail&amp;quot; folder, \/boot\/home\/mail\/. (You probably have a simlink in there now called &amp;quot;mailbox&amp;quot; that links to the &amp;quot;in&amp;quot; folder). Now whenever I double-click on the mailbox in the Deskbar, it runs the script instead of opening my &amp;quot;in&amp;quot; folder. To complete the process, if it moved new beusertalk mail into the New folder it opens it up and then the last line of the script opens my in box.<\/p>\n<pre>\ntargetfolder=$HOME\/mail\/BeUserTalk\/New\/\nsearchword=beusertalk\nmovedmail=no\nnewmail=$(query\n \"((MAIL:status=='*[nN][eE][wW]*')&amp;&amp;(BEOS:TYPE=='text\/x-email'))\")\nfor i in ${newmail\/\/ \/\\}; do\n\t# replace backlashes with spaces again\n\tfile=\"${i\/\/\\\/ }\"\n\t# if file contain the searched-for word, then move it to target folder\n\tif grep -ic \"$searchword\" \"$file\"; then\n\t\tfilename=\"${file##\/*\/}\"\n\t\tif [ ! -e \"$targetfolder$filename\" ]; then\n\t\t\tmv \"$file\" \"$targetfolder\"\n\t\t\tmovedmail=yes\n\t\tfi\n\tfi\ndone\n\/boot\/beos\/system\/Tracker $HOME\/mail\/in\nif [ \"$movedmail\" = yes ]; then\n\t\/boot\/beos\/system\/Tracker \"$targetfolder\"\nfi\n<\/pre>\n<p>One word of warning: If this script ends up moving a bunch of files, it might take a second or two before your &amp;quot;in&amp;quot; folder actually opens. You can move this line to the beginning of the script, if you don&#8217;t mind watching your email disappear.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever wanted to filter your BeMail into a given folder after downloading? Although Be&#8217;s built-in Find function is powerful and can be run from the command line (see Queries from Terminal), the problem with querying BeMail is that you can&#8217;t query all the attibutes you might like (e.g., &amp;quot;CC:&amp;quot;). The following BASH script [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[2],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","tag-applications"],"_links":{"self":[{"href":"https:\/\/www.betips.net\/index.php?rest_route=\/wp\/v2\/posts\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.betips.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.betips.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.betips.net\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.betips.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=213"}],"version-history":[{"count":0,"href":"https:\/\/www.betips.net\/index.php?rest_route=\/wp\/v2\/posts\/213\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.betips.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.betips.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.betips.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}