Error when viewing mails.
[notmuch-archives.git] / f2 / 61fd0551708223a87e26ea1c780dd764e982ba
1 Return-Path: <prvs=3767ca334=jrosenthal@jhu.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id E3B07431FAF\r
6         for <notmuch@notmuchmail.org>; Mon,  6 Feb 2012 10:29:08 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id CG-8x8yjb-fm for <notmuch@notmuchmail.org>;\r
16         Mon,  6 Feb 2012 10:29:08 -0800 (PST)\r
17 Received: from ipex1.johnshopkins.edu (ipex1.johnshopkins.edu [162.129.8.141])\r
18         (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id E4D24431FAE\r
21         for <notmuch@notmuchmail.org>; Mon,  6 Feb 2012 10:29:07 -0800 (PST)\r
22 X-IronPort-AV: E=Sophos;i="4.73,372,1325480400"; d="scan'208";a="126653374"\r
23 Received: from pool-173-52-130-33.nycmny.east.verizon.net (HELO gogo)\r
24         ([173.52.130.33])\r
25         by ipex1.johnshopkins.edu with ESMTP/TLS/AES256-SHA;\r
26         06 Feb 2012 13:29:06 -0500\r
27 Received: from jkr by gogo with local (Exim 4.76)\r
28         (envelope-from <jrosenthal@jhu.edu>)\r
29         id 1RuTJJ-0003M8-Fc; Mon, 06 Feb 2012 13:29:05 -0500\r
30 From: Jesse Rosenthal <jrosenthal@jhu.edu>\r
31 To: Tomi Ollila <tomi.ollila@iki.fi>, Tamas Papp <tkpapp@gmail.com>,\r
32         notmuch@notmuchmail.org\r
33 Subject: Re: newbie questions\r
34 In-Reply-To: <m2aa4w78v0.fsf@guru.guru-group.fi>\r
35 References: <20120203115934.GA5605@daedalus>\r
36         <m2aa4w78v0.fsf@guru.guru-group.fi>\r
37 User-Agent: Notmuch/0.11+137~g7cd907b (http://notmuchmail.org) Emacs/24.0.93.1\r
38         (i686-pc-linux-gnu)\r
39 Date: Mon, 06 Feb 2012 13:29:05 -0500\r
40 Message-ID: <877gzz4xzi.fsf@jhu.edu>\r
41 MIME-Version: 1.0\r
42 Content-Type: text/plain\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Mon, 06 Feb 2012 18:29:09 -0000\r
56 \r
57 On Mon, 06 Feb 2012 08:51:15 +0200, Tomi Ollila <tomi.ollila@iki.fi> wrote:\r
58 > On Fri, 3 Feb 2012 12:59:34 +0100, Tamas Papp <tkpapp@gmail.com> wrote:\r
59 > > \r
60 > > 1. How can I restrict searches (eg of my inbox) to the last few\r
61 > > messages (eg 50-100) or some date (eg last 2 weeks)?  I am using the\r
62 > > Emacs interface.\r
63\r
64 > Currently, if you have GNU date you can run from command line:\r
65\r
66 > date +%s.. --date '2 weeks ago'\r
67\r
68 > Then paste the string 1327300096.. to the search field.\r
69 \r
70 FWIW, I actually have a hacky date parser baked into my\r
71 remote-usage-and-other-stuff script (a more idiosyncratc python\r
72 version of the bash script on the wiki). I found that I needed\r
73 date-searching pretty frequently, since language and senders seem to be\r
74 repeated pretty often in my world. It just parses a "date:" term, passes\r
75 it to GNU date, and proceeds with a term in notmuch language. It also\r
76 does some day-rounding, since by "date:'2 days ago'..yesterday", I mean\r
77 "beginning of day before yesterday to end of yesterday," not "48 hours\r
78 ago until 24 hours ago."\r
79 \r
80 I'm not swearing by its efficiency, or even its correctness, but it has\r
81 made my life easier. The basics are as follows:\r
82 \r
83     DATE_PATTERN = re.compile(r'^date:([^.]+)(\.\.)?([^.]+)?')\r
84     \r
85     def replace_date_args(st):\r
86         out = subprocess.check_output([GNU_DATE, "+%s", "-d", st])\r
87         return out.strip()\r
88     \r
89     def round_day_down(timestamp):\r
90         tup = datetime.fromtimestamp(int(timestamp)).date().timetuple()\r
91         return time.mktime(tup)\r
92     \r
93     def round_day_up(timestamp):\r
94         date = datetime.fromtimestamp(int(timestamp)).date()\r
95         date += timedelta(days=1)\r
96         tup = date.timetuple()\r
97         return time.mktime(tup)\r
98     \r
99     def parse_date_args(st):\r
100         re_match = DATE_PATTERN.match(st)\r
101         if re_match:\r
102             grps = re_match.groups()\r
103             start_term = grps[0]\r
104             if not (grps[1] or grps[2]):\r
105                 stop_term = start_term\r
106             elif not grps[2]:\r
107                 stop_term = "now"\r
108             else:\r
109                 stop_term = grps[2]\r
110     \r
111             try:\r
112                 start = round_day_down(replace_date_args(start_term))\r
113                 stop = round_day_up(replace_date_args(stop_term))\r
114                 return "%d..%d" % (start, stop)\r
115             except OSError:\r
116                 return st\r
117         else:\r
118             return st\r
119 \r
120 And then in the main routine, I have a parse-and-replace step:\r
121 \r
122     args = sys.argv[1:]\r
123     try:\r
124         if args[-1] == ")'":\r
125             args = args[:-2] + shlex.split(sys.argv[-2]) + [")'"]\r
126         else:\r
127             args = args[:-1] + shlex.split(sys.argv[-1])\r
128     except IndexError, ValueError:\r
129         pass\r
130 \r
131     args = [parse_date_args(a) for a in args] \r
132 \r
133 I'm only giving the relevant parts here, of course.\r
134 \r
135 Best,\r
136 Jesse\r
137     \r
138 \r