1 Return-Path: <glasse@cs.rpi.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 0C02F431E84
\r
6 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:08:14 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3,
\r
14 RCVD_IN_SORBS_WEB=0.614] autolearn=disabled
\r
15 Received: from olra.theworths.org ([127.0.0.1])
\r
16 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id Z5T4hwHmdNMx for <notmuch@notmuchmail.org>;
\r
18 Wed, 15 Feb 2012 14:08:10 -0800 (PST)
\r
19 Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu
\r
20 [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
21 (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS
\r
22 id CC196431E62 for <notmuch@notmuchmail.org>; Wed, 15 Feb 2012 14:08:09 -0800
\r
25 S|ab6d52123042524f17ae1cbf5371e0f7ad136fdb|dc8a24c5bb94d39980edb37ffe428d08
\r
26 X-Countries: Cameroon, United States
\r
27 X-SMTP-From: accepted <glasse@cs.rpi.edu> [195.24.209.20] [195.24.209.20]
\r
28 (localhost) {Cameroon}
\r
29 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from
\r
30 :to:cc:subject:date:message-id:in-reply-to:references; s=
\r
31 default; i=glasse@cs.rpi.edu; t=1329343687; x=1329948487; l=4043;
\r
32 bh=LUFsjn2hMG717omq6T++K0okDCY=; b=o51Wm0PLX0QMhVbynToyM41
\r
33 xT4a+6d2m6W0EejAWZNNjdTViDbWwcK9/NvLNQOPPz4rTI4rL4JmwFGJ/Q5xRjCB
\r
34 lX/ywNJfjtu2Uzo4CbBtt9xBMyhrx2lcNAYNSwg2UFyzn9zAAY/9UTwa9LwSn1e2
\r
35 6g4rqDeMntMfk2Lj7/do=
\r
36 DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc
\r
37 :subject:date:message-id:in-reply-to:references; q=dns; s=
\r
38 default; b=qgZc53kWMg5BGk85wGJEKucipxOa6jej8bYqNYC4MYBQnXdPtHFJm
\r
39 c5FuSmR7ewW9uUU0+aHkS2Or/r+tBAkCIQGXTs4JoDzJDdt9CF010LqZY6hR93IZ
\r
40 /6+peXGf/vD2zRDkM8BMmM9ZDB5XvUQgrrbEvnZ7vWNtGrGzGEtoOE=
\r
41 X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00
\r
42 X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit
\r
44 Authentication-Results: cliffclavin.cs.rpi.edu;
\r
45 DKIM=neutral (none) header.from=glasse@cs.rpi.edu;
\r
47 Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu
\r
48 X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FM7Ywh008805 Auth:glasse
\r
49 X-Virus-Scanned-By: cliffclavin.cs.rpi.edu
\r
50 Received: from localhost ([195.24.209.20]) (authenticated bits=0)
\r
51 by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FM7Ywh008805
\r
52 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO);
\r
53 Wed, 15 Feb 2012 17:07:48 -0500 (EST)
\r
54 (envelope-from glasse@cs.rpi.edu)
\r
55 From: Ethan Glasser-Camp <glasse@cs.rpi.edu>
\r
56 To: notmuch@notmuchmail.org
\r
57 Subject: [RFC PATCH 05/13] notmuch_database_add_message calculates sha1 of
\r
58 messages using mailstore
\r
59 Date: Wed, 15 Feb 2012 17:01:58 -0500
\r
60 Message-Id: <1329343326-16410-6-git-send-email-glasse@cs.rpi.edu>
\r
61 X-Mailer: git-send-email 1.7.5.4
\r
62 In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>
\r
63 References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu>
\r
64 X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25
\r
65 Cc: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
66 X-BeenThere: notmuch@notmuchmail.org
\r
67 X-Mailman-Version: 2.1.13
\r
69 List-Id: "Use and development of the notmuch mail system."
\r
70 <notmuch.notmuchmail.org>
\r
71 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
72 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
74 List-Post: <mailto:notmuch@notmuchmail.org>
\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
76 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
77 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
78 X-List-Received-Date: Wed, 15 Feb 2012 22:08:14 -0000
\r
80 From: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
82 Previously, notmuch_database_add_message used the notmuch_sha1_of_file
\r
83 function, which accesses a mail file directly. Create a new function
\r
84 called notmuch_sha1_of_message which uses a mailstore to access the
\r
85 file, and use that instead.
\r
87 Also, as a drive-by cleanup, use the named constant BLOCK_SIZE instead
\r
88 of the integer literal 4096.
\r
90 Signed-off-by: Ethan Glasser-Camp <ethan@betacantrips.com>
\r
92 lib/database.cc | 2 +-
\r
93 lib/notmuch-private.h | 3 ++
\r
94 lib/sha1.c | 52 ++++++++++++++++++++++++++++++++++++------------
\r
95 3 files changed, 43 insertions(+), 14 deletions(-)
\r
97 diff --git a/lib/database.cc b/lib/database.cc
\r
98 index e3c8095..ff44e76 100644
\r
99 --- a/lib/database.cc
\r
100 +++ b/lib/database.cc
\r
101 @@ -1700,7 +1700,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
102 if (message_id == NULL ) {
\r
103 /* No message-id at all, let's generate one by taking a
\r
104 * hash over the file's contents. */
\r
105 - char *sha1 = notmuch_sha1_of_file (filename);
\r
106 + char *sha1 = notmuch_sha1_of_message (notmuch->mailstore, filename);
\r
108 /* If that failed too, something is really wrong. Give up. */
\r
109 if (sha1 == NULL) {
\r
110 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
111 index 0f01437..2589928 100644
\r
112 --- a/lib/notmuch-private.h
\r
113 +++ b/lib/notmuch-private.h
\r
114 @@ -454,6 +454,9 @@ notmuch_sha1_of_string (const char *str);
\r
116 notmuch_sha1_of_file (const char *filename);
\r
119 +notmuch_sha1_of_message (notmuch_mailstore_t *mailstore, const char *filename);
\r
121 /* string-list.c */
\r
123 typedef struct _notmuch_string_node {
\r
124 diff --git a/lib/sha1.c b/lib/sha1.c
\r
125 index cc48108..ea25999 100644
\r
128 @@ -64,19 +64,11 @@ notmuch_sha1_of_string (const char *str)
\r
129 return _hex_of_sha1_digest (digest);
\r
132 -/* Create a hexadecimal string version of the SHA-1 digest of the
\r
133 - * contents of the named file.
\r
135 - * This function returns a newly allocated string which the caller
\r
136 - * should free() when finished.
\r
138 - * If any error occurs while reading the file, (permission denied,
\r
139 - * file not found, etc.), this function returns NULL.
\r
140 +/* Internal function to feed the contents of a FILE * to the sha1 functions.
\r
143 -notmuch_sha1_of_file (const char *filename)
\r
145 +_notmuch_sha1_of_filep (FILE *file)
\r
148 #define BLOCK_SIZE 4096
\r
149 unsigned char block[BLOCK_SIZE];
\r
151 @@ -84,14 +76,13 @@ notmuch_sha1_of_file (const char *filename)
\r
152 unsigned char digest[SHA1_DIGEST_SIZE];
\r
155 - file = fopen (filename, "r");
\r
159 sha1_begin (&sha1);
\r
162 - bytes_read = fread (block, 1, 4096, file);
\r
163 + bytes_read = fread (block, 1, BLOCK_SIZE, file);
\r
164 if (bytes_read == 0) {
\r
167 @@ -113,3 +104,38 @@ notmuch_sha1_of_file (const char *filename)
\r
171 +/* Create a hexadecimal string version of the SHA-1 digest of the
\r
172 + * contents of the named file.
\r
174 + * This function returns a newly allocated string which the caller
\r
175 + * should free() when finished.
\r
177 + * If any error occurs while reading the file, (permission denied,
\r
178 + * file not found, etc.), this function returns NULL.
\r
181 +notmuch_sha1_of_file (const char *filename)
\r
185 + file = fopen (filename, "r");
\r
186 + return _notmuch_sha1_of_filep (file);
\r
189 +/* Create a hexadecimal string version of the SHA-1 digest of the
\r
190 + * contents of the named message, which is accessed via a mailstore.
\r
192 + * This function returns a newly allocated string which the caller
\r
193 + * should free() when finished.
\r
195 + * If any error occurs while reading the file, (permission denied,
\r
196 + * file not found, etc.), this function returns NULL.
\r
199 +notmuch_sha1_of_message (notmuch_mailstore_t *mailstore, const char *filename)
\r
203 + file = notmuch_mailstore_open (mailstore, filename);
\r
204 + return _notmuch_sha1_of_filep (file);
\r