Subject: misc/34456: sent-pr.el: to use smtpmail.el instead of /usr/bin/send-pr
To: None <misc-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <cheusov@tut.by>
List: netbsd-bugs
Date: 09/02/2006 18:10:01
>Number:         34456
>Category:       misc
>Synopsis:       sent-pr.el: to use smtpmail.el instead of /usr/bin/send-pr
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    misc-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Sep 02 18:10:01 +0000 2006
>Originator:     cheusov@tut.by
>Release:        NetBSD 3.0_STABLE
>Organization:
Best regards, Aleksey Cheusov.
>Environment:
System: NetBSD chen.chizhovka.net 3.0_STABLE NetBSD 3.0_STABLE (GENERIC) #2: Sun Mar 12 12:49:58 GMT 2006 cheusov@chen:/usr/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
motd.current and motd.beta claims that there are two ways for reporting bugs.
There is the third one, to use send-pr.el from Emacs editor.
For me personally this is much more convenient because
this way does require neither www browser nor expert knowledge in MTA
configuring. For this to work I created a small patchc which is below.

example ~/.emacs:

(let* ((path "/usr/share/gnats")
       (file (concat path "/send-pr.el")))
  (if (file-exists-p file)
      (let ((load-path (cons path load-path)))
	(require 'send-pr)
	(setq gnats::use-mail-send-and-exit t))))

For this
>Fix:
Index: send-pr-el.in
===================================================================
RCS file: /cvsroot/src/gnu/usr.bin/send-pr/send-pr-el.in,v
retrieving revision 1.5
diff -u -r1.5 send-pr-el.in
--- send-pr-el.in	7 Sep 1995 00:21:14 -0000	1.5
+++ send-pr-el.in	2 Sep 2006 16:50:00 -0000
@@ -41,10 +41,11 @@
 ;;;;---------------------------------------------------------------------------
 
 (provide 'send-pr)
+(require 'smtpmail)
 
 ;;;;---------------------------------------------------------------------------
 ;;;; Customization: put the following forms into your default.el file
-;;;; (or into your .emacs)
+;;;; (or into your .emacs) and/or initialize the described below variables
 ;;;;---------------------------------------------------------------------------
 
 ;(autoload 'send-pr-mode "send-pr"
@@ -53,6 +54,15 @@
 ;(autoload 'send-pr "send-pr"
 ;	  	  "Command to create and send a problem report." t)
 
+; defcustom should be used here
+(defvar gnats::use-mail-send-and-exit nil
+  "If t, send the problem report using mail-send-and-exit function
+from smtpmail.el instead of the send-pr command line executable.")
+
+; defcustom should be used here
+(defvar gnats::mail-send-and-exit-arg nil
+  "argument passed to mail-send-and-exit function")
+
 ;;;;---------------------------------------------------------------------------
 ;;;; End of Customization Section
 ;;;;---------------------------------------------------------------------------
@@ -308,11 +318,11 @@
 		    send-pr::template-alist))))))
 
 (fset 'do-send-pr 'send-pr:submit-pr)	;backward compat
-(defun send-pr:submit-pr ()
+
+(defun send-pr:submit-pr-using-send-pr-executable ()
   "Pipe the contents of the buffer *send-pr* to `send-pr -f -.' unless this
 buffer was loaded with emacsclient, in which case save the buffer and exit."
   ;;
-  (interactive)
   (cond
    ((and (boundp 'server-buffer-clients)
 	 server-buffer-clients)
@@ -353,7 +363,21 @@
    (t
     (save-buffer)
     (message "Exit emacs to send the PR."))))
-   
+
+(defun send-pr:submit-pr ()
+  "Either send e-mail using mail-send-and-exit function from smtpmail.el
+or pipe the contents of the buffer *send-pr* to `send-pr -f -.' unless this
+buffer was loaded with emacsclient, in which case save the buffer and exit."
+  ;;
+  (interactive)
+  (if gnats::use-mail-send-and-exit
+      (progn
+       (gnats::prepare-to-send)
+       (mail-send-and-exit gnats::mail-send-and-exit-arg)
+       )
+    (send-pr:submit-pr-using-send-pr-executable)
+    ))
+
 ;;;;---------------------------------------------------------------------------
 ;;;; send-pr:send-pr-mode mode
 ;;;;---------------------------------------------------------------------------
@@ -488,6 +512,29 @@
 	  ((gnats::functionp thing) thing)
 	  (t (error "ACK")))))
 
+(defun gnats::remove-SEND-PR-lines ()
+  (interactive)
+  "Removes SEND-PR lines in the current buffer."
+  (goto-char (point-min))
+  (while (search-forward-regexp "^SEND-PR" nil t)
+    (beginning-of-line)
+    (kill-line t)))
+
+(defun gnats::remove-pattern-lines ()
+  (interactive)
+  "Removes <pattern> lines in the current buffer."
+  (goto-char (point-min))
+  (while (search-forward-regexp "^\t<.*>$" nil t)
+    (beginning-of-line)
+    (kill-line t)))
+
+(defun gnats::prepare-to-send ()
+  "Remove unnecessary lines before sending e-mail."
+  (save-excursion
+    (gnats::remove-SEND-PR-lines)
+    (gnats::remove-pattern-lines)
+    ))
+
 ;;;;---------------------------------------------------------------------------
 ;;;; Point movement functions
 ;;;;---------------------------------------------------------------------------