Re: newbie questions
authorJesse Rosenthal <jrosenthal@jhu.edu>
Mon, 6 Feb 2012 18:29:05 +0000 (13:29 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:13 +0000 (09:44 -0800)
f2/61fd0551708223a87e26ea1c780dd764e982ba [new file with mode: 0644]

diff --git a/f2/61fd0551708223a87e26ea1c780dd764e982ba b/f2/61fd0551708223a87e26ea1c780dd764e982ba
new file mode 100644 (file)
index 0000000..86359e0
--- /dev/null
@@ -0,0 +1,138 @@
+Return-Path: <prvs=3767ca334=jrosenthal@jhu.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id E3B07431FAF\r
+       for <notmuch@notmuchmail.org>; Mon,  6 Feb 2012 10:29:08 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id CG-8x8yjb-fm for <notmuch@notmuchmail.org>;\r
+       Mon,  6 Feb 2012 10:29:08 -0800 (PST)\r
+Received: from ipex1.johnshopkins.edu (ipex1.johnshopkins.edu [162.129.8.141])\r
+       (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id E4D24431FAE\r
+       for <notmuch@notmuchmail.org>; Mon,  6 Feb 2012 10:29:07 -0800 (PST)\r
+X-IronPort-AV: E=Sophos;i="4.73,372,1325480400"; d="scan'208";a="126653374"\r
+Received: from pool-173-52-130-33.nycmny.east.verizon.net (HELO gogo)\r
+       ([173.52.130.33])\r
+       by ipex1.johnshopkins.edu with ESMTP/TLS/AES256-SHA;\r
+       06 Feb 2012 13:29:06 -0500\r
+Received: from jkr by gogo with local (Exim 4.76)\r
+       (envelope-from <jrosenthal@jhu.edu>)\r
+       id 1RuTJJ-0003M8-Fc; Mon, 06 Feb 2012 13:29:05 -0500\r
+From: Jesse Rosenthal <jrosenthal@jhu.edu>\r
+To: Tomi Ollila <tomi.ollila@iki.fi>, Tamas Papp <tkpapp@gmail.com>,\r
+       notmuch@notmuchmail.org\r
+Subject: Re: newbie questions\r
+In-Reply-To: <m2aa4w78v0.fsf@guru.guru-group.fi>\r
+References: <20120203115934.GA5605@daedalus>\r
+       <m2aa4w78v0.fsf@guru.guru-group.fi>\r
+User-Agent: Notmuch/0.11+137~g7cd907b (http://notmuchmail.org) Emacs/24.0.93.1\r
+       (i686-pc-linux-gnu)\r
+Date: Mon, 06 Feb 2012 13:29:05 -0500\r
+Message-ID: <877gzz4xzi.fsf@jhu.edu>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 06 Feb 2012 18:29:09 -0000\r
+\r
+On Mon, 06 Feb 2012 08:51:15 +0200, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
+> On Fri, 3 Feb 2012 12:59:34 +0100, Tamas Papp <tkpapp@gmail.com> wrote:\r
+> > \r
+> > 1. How can I restrict searches (eg of my inbox) to the last few\r
+> > messages (eg 50-100) or some date (eg last 2 weeks)?  I am using the\r
+> > Emacs interface.\r
+> \r
+> Currently, if you have GNU date you can run from command line:\r
+> \r
+> date +%s.. --date '2 weeks ago'\r
+> \r
+> Then paste the string 1327300096.. to the search field.\r
+\r
+FWIW, I actually have a hacky date parser baked into my\r
+remote-usage-and-other-stuff script (a more idiosyncratc python\r
+version of the bash script on the wiki). I found that I needed\r
+date-searching pretty frequently, since language and senders seem to be\r
+repeated pretty often in my world. It just parses a "date:" term, passes\r
+it to GNU date, and proceeds with a term in notmuch language. It also\r
+does some day-rounding, since by "date:'2 days ago'..yesterday", I mean\r
+"beginning of day before yesterday to end of yesterday," not "48 hours\r
+ago until 24 hours ago."\r
+\r
+I'm not swearing by its efficiency, or even its correctness, but it has\r
+made my life easier. The basics are as follows:\r
+\r
+    DATE_PATTERN = re.compile(r'^date:([^.]+)(\.\.)?([^.]+)?')\r
+    \r
+    def replace_date_args(st):\r
+        out = subprocess.check_output([GNU_DATE, "+%s", "-d", st])\r
+        return out.strip()\r
+    \r
+    def round_day_down(timestamp):\r
+        tup = datetime.fromtimestamp(int(timestamp)).date().timetuple()\r
+        return time.mktime(tup)\r
+    \r
+    def round_day_up(timestamp):\r
+        date = datetime.fromtimestamp(int(timestamp)).date()\r
+        date += timedelta(days=1)\r
+        tup = date.timetuple()\r
+        return time.mktime(tup)\r
+    \r
+    def parse_date_args(st):\r
+        re_match = DATE_PATTERN.match(st)\r
+        if re_match:\r
+            grps = re_match.groups()\r
+            start_term = grps[0]\r
+            if not (grps[1] or grps[2]):\r
+                stop_term = start_term\r
+            elif not grps[2]:\r
+                stop_term = "now"\r
+            else:\r
+                stop_term = grps[2]\r
+    \r
+            try:\r
+                start = round_day_down(replace_date_args(start_term))\r
+                stop = round_day_up(replace_date_args(stop_term))\r
+                return "%d..%d" % (start, stop)\r
+            except OSError:\r
+                return st\r
+        else:\r
+            return st\r
+\r
+And then in the main routine, I have a parse-and-replace step:\r
+\r
+    args = sys.argv[1:]\r
+    try:\r
+        if args[-1] == ")'":\r
+            args = args[:-2] + shlex.split(sys.argv[-2]) + [")'"]\r
+        else:\r
+            args = args[:-1] + shlex.split(sys.argv[-1])\r
+    except IndexError, ValueError:\r
+        pass\r
+\r
+    args = [parse_date_args(a) for a in args] \r
+\r
+I'm only giving the relevant parts here, of course.\r
+\r
+Best,\r
+Jesse\r
+    \r
+\r