From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id D7A2A6DE25E8 for ; Mon, 19 Mar 2018 12:25:24 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.296 X-Spam-Level: X-Spam-Status: No, score=-0.296 tagged_above=-999 required=5 tests=[AWL=-0.297, UNPARSEABLE_RELAY=0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UY_uGI9ze6JE for ; Mon, 19 Mar 2018 12:25:23 -0700 (PDT) Received: from marcos.anarc.at (marcos.anarc.at [206.248.172.91]) by arlo.cworth.org (Postfix) with ESMTPS id 9D1F36DE25B5 for ; Mon, 19 Mar 2018 12:25:23 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: anarcat) with ESMTPSA id D78B710E04F From: =?utf-8?Q?Antoine_Beaupr=C3=A9?= To: notmuch@notmuchmail.org Subject: tip: how to not forget attachments In-Reply-To: <874llc2bkp.fsf@curie.anarc.at> References: <87d10042pu.fsf@curie.anarc.at> <87woy8vx7i.fsf@tesseract.cs.unb.ca> <87a7v42bv9.fsf@curie.anarc.at> <874llc2bkp.fsf@curie.anarc.at> Date: Mon, 19 Mar 2018 15:25:20 -0400 Message-ID: <87fu4v27hb.fsf@curie.anarc.at> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Mar 2018 19:25:25 -0000 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2018-03-19 13:56:54, Antoine Beaupr=C3=A9 wrote: > PS: don't we have a "you forgot to actually attach the damn file" plugin > when we detect the word "attachment" and there's no attach? :p So I figured that one out, I think. Before adding it to the wiki, I'd like a review of the code (attached) from more adept elisp programmers. I'm particularly surprised that save-excursion doesn't work the way I expect: when I answer "no" to the question, I go back to the email buffer, but the point is invariably at the end of the buffer, whereas I would expect it to be where it was when I send the message. It looks like something else moves the mark before my hook, but I'm not sure what... How else than (error) or (keyboard-quit) am I supposed to abort email sending? (message-send) uses the latter but it would seem better to use an actual error message than to just "beep" our way out here.. Other advice? (save-excursion) + (goto-char (point-min)) + (re-search-forward), is that idiomatic? or is there something more clever that should be done? thanks! --=20 Tu conna=C3=AEtras la v=C3=A9rit=C3=A9 de ton chemin =C3=A0 ce qui te rend = heureux. - Aristote --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=notmuch-buddha.el Content-Transfer-Encoding: quoted-printable (defvar anarcat/notmuch-attach-regex "\\b\\(attache\?ment\\|attached\\)\\b" "what is considered a reference to an attachment in an email body by the attachment detection hook") (defun anarcat/notmuch-check-attach () (save-mark-and-excursion ;; this fails somehow: point is at the end of th= e buffer on error (goto-char (point-min)) (if (re-search-forward anarcat/notmuch-attach-regex nil t) (progn=20 (goto-char (point-min)) (unless (re-search-forward "<#part [^>]*filename=3D[^>]*>" nil t) (or (y-or-n-p "Email seem to refer to attachment, but nothing a= ttached, send anyways?") (error "No attachment found, aborting"))))))) (add-hook 'message-send-hook 'anarcat/notmuch-check-attach) --=-=-=--