From mboxrd@z Thu Jan  1 00:00:00 1970
Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail
From: Jakub =?UTF-8?Q?Je=C4=8Dm=C3=ADnek?= <jecminek.k@gmail.com>
Newsgroups: gmane.emacs.bugs
Subject: bug#61002: 28.2; Gnus - "Date" scoring scores all articles.
Date: Mon, 12 Feb 2024 16:58:30 +0100
Message-ID: <m2v86t3c9l.fsf@gmail.com>
References: <878rhvhsyu.fsf@alfa.kjonca> <m2a5p0svwt.fsf@gmail.com>
 <m2plxwz1c8.fsf_-_@gmail.com> <86ttmz86o3.fsf@gnu.org>
 <86h6igvj1n.fsf@gnu.org> <87bk8oz0u0.fsf@ericabrahamsen.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214";
	logging-data="29551"; mail-complaints-to="usenet@ciao.gmane.io"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cc: 61002@debbugs.gnu.org, Eli Zaretskii <eliz@gnu.org>, kjonca@poczta.onet.pl,
 larsi@gnus.org
To: Eric Abrahamsen <eric@ericabrahamsen.net>
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 12 16:58:56 2024
Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>
Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org
Original-Received: from lists.gnu.org ([209.51.188.17])
	by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
	(Exim 4.92)
	(envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>)
	id 1rZYhr-0007RN-M7
	for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Feb 2024 16:58:55 +0100
Original-Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <bug-gnu-emacs-bounces@gnu.org>)
	id 1rZYhk-0008O4-Mv; Mon, 12 Feb 2024 10:58:48 -0500
Original-Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1rZYhi-0008Jf-Ks
 for bug-gnu-emacs@gnu.org; Mon, 12 Feb 2024 10:58:46 -0500
Original-Received: from debbugs.gnu.org ([2001:470:142:5::43])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>)
 id 1rZYhi-00074x-9o
 for bug-gnu-emacs@gnu.org; Mon, 12 Feb 2024 10:58:46 -0500
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
 (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1rZYhy-0005SI-Jy
 for bug-gnu-emacs@gnu.org; Mon, 12 Feb 2024 10:59:02 -0500
X-Loop: help-debbugs@gnu.org
Resent-From: Jakub =?UTF-8?Q?Je=C4=8Dm=C3=ADnek?= <jecminek.k@gmail.com>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Mon, 12 Feb 2024 15:59:02 +0000
Resent-Message-ID: <handler.61002.B61002.170775354020957@debbugs.gnu.org>
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 61002
X-GNU-PR-Package: emacs
Original-Received: via spool by 61002-submit@debbugs.gnu.org id=B61002.170775354020957
 (code B ref 61002); Mon, 12 Feb 2024 15:59:02 +0000
Original-Received: (at 61002) by debbugs.gnu.org; 12 Feb 2024 15:59:00 +0000
Original-Received: from localhost ([127.0.0.1]:38486 helo=debbugs.gnu.org)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>)
 id 1rZYhw-0005Rw-2S
 for submit@debbugs.gnu.org; Mon, 12 Feb 2024 10:59:00 -0500
Original-Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]:61445)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jecminek.k@gmail.com>) id 1rZYhs-0005RD-KY
 for 61002@debbugs.gnu.org; Mon, 12 Feb 2024 10:58:57 -0500
Original-Received: by mail-ej1-x633.google.com with SMTP id
 a640c23a62f3a-a2a17f3217aso436105066b.2
 for <61002@debbugs.gnu.org>; Mon, 12 Feb 2024 07:58:39 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1707753513; x=1708358313; darn=debbugs.gnu.org;
 h=content-transfer-encoding:mime-version:user-agent:message-id:date
 :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=X4Hg5aP0uO4K+BwGtXht84qF44HXMuJS8MTZoNuutf8=;
 b=eGaNKxbHPCKn7h8oT78mtX2GGH19ShseGndATwXlKY2X/IQmxx0TggJHI8SvNKoSQO
 v43ZWR8E7f6KfeWTjmwGLvQPckhD8Oi5WwPin1OTJxXwg/Z0cGnu3y/D0YO1AHN0/FaJ
 uUCQI0cGxNlABxZw+mD+gaQyywG7MXA5soLspRI5oIwZ/bWpfou5+ggudibuW1SIgTLH
 wNCZqIasUhzi6QIeULEQiAUBlp7wJ1QtUGY4E4B+frKRUYUC4znbV1WCz3GjVG5/rIvu
 0TFn2jJlIHFXRb0v4lN1WrxEnTuTQOyGLAJ5gMcmakwu8ohG/wkugVw6BNclEANWY/zw
 U4NQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1707753513; x=1708358313;
 h=content-transfer-encoding:mime-version:user-agent:message-id:date
 :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from
 :to:cc:subject:date:message-id:reply-to;
 bh=X4Hg5aP0uO4K+BwGtXht84qF44HXMuJS8MTZoNuutf8=;
 b=p/rEEjRsVK8Azz9SN6VCQobCbqVhTzhu5IStTWUcsBJ2M9zWJKN80mcRvTaemerJPg
 76kDepHUEje+oK2GaW0T8p5qWyiRNMq109bWlZcryF+s8mGx8seF53BwW/RS6iHCqY22
 /i/tcXOsH74CoTWboeHyqgRj89w4bxkyLQR7eChgw4wMknLWNgekJP63Z2tjLdXVAclq
 YUUOok9RdO+MV5ninT6G41nSR15QMk1D7WgBPvDKtj6GBAjqXtkozCTV1gl3Pfu2OOfI
 WmCXOABPO5SzhbcmWscXfdsKCh0c2Fsy+ZbkwcY3ekdVakpghi/xv2Rg1g2LQYXCjEKY
 gB8A==
X-Forwarded-Encrypted: i=1;
 AJvYcCVO4RF5GMv/ICJ/LoAvH+RyhfE6Fa5iJWkI1SMenoVKcgFZsKbUoYUs9KrqcY3u1S0aMIrSoRkmfzwXBKvj/qMksDV9QBs=
X-Gm-Message-State: AOJu0YwPuICE0tk7HdR4DKzLnIDXEdOkSfvXFmCnNl2Hkkqw4S0ZsUMw
 dJONfiAVSdGkZEXRw2GjpgA23QlclfNtVIYcO7XBMa3IkW+mqYi12aABNwcqJBA=
X-Google-Smtp-Source: AGHT+IGe6QtukH7E/e5nTSJdKAUH5QdYVKbtKCXXvY6razKEKQkVBIq6LKRr5ulk6biYPODKOa4VQA==
X-Received: by 2002:a17:906:2894:b0:a38:423c:771c with SMTP id
 o20-20020a170906289400b00a38423c771cmr4925127ejd.17.1707753513016; 
 Mon, 12 Feb 2024 07:58:33 -0800 (PST)
X-Forwarded-Encrypted: i=1;
 AJvYcCWkjEKggfZ4UrjJ4Hmw0WlWjAVWZ2LIcdVG5/kM95GA0BNDWQF/qMIP44vsEn1siqLRoUbNrZFEUxeIxc2TF7jXSMrNEqBvdlF91nEwevlH5uOO82CMnJf1ktGdUdmo3qwySYZwpkGjNpIman0=
Original-Received: from Jakubs-MacBook-Air.local ([185.249.114.4])
 by smtp.gmail.com with ESMTPSA id
 d13-20020a170906370d00b00a3c66ac5146sm329656ejc.120.2024.02.12.07.58.32
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 12 Feb 2024 07:58:32 -0800 (PST)
In-Reply-To: <87bk8oz0u0.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of
 "Sat, 10 Feb 2024 09:27:35 -0800")
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
 the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe>
List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs>
List-Post: <mailto:bug-gnu-emacs@gnu.org>
List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>,
 <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe>
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org
Xref: news.gmane.io gmane.emacs.bugs:279901
Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/279901>

Hi, thanks for the feedback!

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Thanks for the ping. TBH I've never used scoring in Gnus, so this is new
> territory for me. I tried the patch and it worked correctly, but...
>
> The patch is doing this:
>
> (gnus-date-get-time (gnus-date-iso8601 match))
>
> This is the definition of `gnus-date-iso8601':
>
> (defun gnus-date-iso8601 (date)
>   "Convert the DATE to YYYYMMDDTHHMMSS."
>   (condition-case ()
>       (gnus-time-iso8601 (gnus-date-get-time date))
>     (error "")))
>
> So error handling aside, the patch ends up doing the equivalent of:
>
> (let ((ds "Sun, 22 Jan 2023 09:30:17 +0100"))
>   (gnus-date-get-time
>    (gnus-time-iso8601
>     (gnus-date-get-time ds))))
>
> which effectively round-trips the date string through two different
> formats.

You're right. I've replaced the offending form with this:

(car (time-convert (gnus-date-get-time match) 1))

> [...] I think we should just keep the inner
> `gnus-date-get-time' call, and wrap the whole `int-to-string' form in a
> `condition-case'. If anything at all goes wrong we really don't care, we
> can just skip it and return a "1" or something.
>
> WDYT?

I believe that error handling is now redundant, because even if we try to
parse invalid date using `gnus-date-get-time' we still end up with valid
value (0).

(/ (car (time-convert (gnus-date-get-time "invalid date") 1)) 86400)

But, there's one important thing I failed to realize - the code I wrote
would break prompts for other headers. Therefore I propose we add `cond'
and distinguish which header we're scoring on.

Please let me know what you think, here's the patch:

>From 4e2174503c1d69345536929a22483ae309048271 Mon Sep 17 00:00:00 2001
From: =3D?UTF-8?q?Jakub=3D20Je=3DC4=3D8Dm=3DC3=3DADnek?=3D <jecminek.k@gmai=
l.com>
Date: Mon, 12 Feb 2024 14:03:24 +0100
Subject: [PATCH] Provide valid match string when scoring on date header
 (Bug#61002)

* lisp/gnus/gnus-score.el (gnus-summary-score-entry): Fix invalid
default match string when creating score file interactively on date header.
---
 lisp/gnus/gnus-score.el | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/lisp/gnus/gnus-score.el b/lisp/gnus/gnus-score.el
index bd19e7d7cd7..479b7496cf1 100644
--- a/lisp/gnus/gnus-score.el
+++ b/lisp/gnus/gnus-score.el
@@ -893,9 +893,14 @@ If optional argument `EXTRA' is non-nil, it's a non-st=
andard overview header."
 				 (t "permanent"))
 			   header
 			   (if (< score 0) "lower" "raise"))
-		   (if (numberp match)
-		       (int-to-string match)
-		     match))))
+                   (cond ((numberp match) (int-to-string match))
+                         ((string=3D header "date")
+                          (int-to-string
+                           (-
+                            (/ (car (time-convert (current-time) 1)) 86400)
+                            (/ (car (time-convert (gnus-date-get-time matc=
h) 1))
+                               86400))))
+                         (t match)))))

     ;; If this is an integer comparison, we transform from string to int.
     (if (eq (nth 2 (assoc header gnus-header-index)) 'gnus-score-integer)
--
2.39.3 (Apple Git-145)

The patch should be correctly indented even though it doesn't look like
it is. The reason is that previous lines contain mixture of tabs and
spaces.

Best

Jakub Je=C4=8Dm=C3=ADnek