🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.vm.bug
Article #8831

Problem with timezone in mail header

#8831
From: Francesco Potorti`
Date: Mon, 19 Apr 1993 14:34
163 lines
6480 bytes
   Timezone names are on their way out in Internet mail and good
   riddance to them.  Programs that generate dates should use numeric
   timezone specifications always and avoid the confusion with the
   names.

   RFC 1123, section 5.2.14
   [...]

A long time ago someone posted a nice patch to sendmail.el, whose
purpose was to write the timezone in mumeric format.  This patch was
not applied to emacs 18.59, I don't know why.  I find it is very
useful, and probably it can solve the problem we are talking about.
It is contained in hunks #1 and #2 of the enclosed context diff.

By the way, the enclosed patch solves another unrelated problem with
FCC.  If the FCC file is visited while sending mail, an error is
raised because the FCC buffer is read only.  Hunk #3 of the enclosed
context diff is a non elegant but functional solution.

*** ../sendmail.el	Thu Mar 26 00:47:16 1992
--- mysendmail.el	Sun Jul  5 18:27:30 1992
***************
*** 256,265 ****
        (if (bufferp errbuf)
  	  (kill-buffer errbuf)))))
  
  (defun mail-do-fcc (header-end)
    (let (fcc-list
  	(rmailbuf (current-buffer))
- 	timezone
  	(tembuf (generate-new-buffer " rmail output"))
  	(case-fold-search t))
      (save-excursion
--- 256,313 ----
        (if (bufferp errbuf)
  	  (kill-buffer errbuf)))))
  
+ 
+ (defvar mail-timezone nil)
+ 
+ (defun mail-get-integer (index)
+   (string-to-int (buffer-substring (match-beginning index) (match-end index))))
+ 
+ (defun mail-get-time (cmd &rest args)
+   (save-excursion
+     (let ((time-in-minutes nil)
+ 	  (scratch-buffer (generate-new-buffer " date output")))
+       (set-buffer scratch-buffer)
+       (erase-buffer)
+       (apply 'call-process cmd nil t nil args)
+       (beginning-of-buffer)
+       (if (re-search-forward "\\([0-9][0-9]\\):\\([0-9][0-9]\\):[0-9][0-9]")
+ 	  (setq time-in-minutes (+ (* (mail-get-integer 1) 60) (mail-get-integer 2)))
+ 	(error (format "Can't parse output of %s to get hour and minutes." cmd))
+ 	)
+       (kill-buffer scratch-buffer)
+       time-in-minutes)))
+ 
+ (defun mail-two-digits (int)
+   (if (< int 10)
+       (format "0%1d" int)
+      (format "%2d" int)))
+ 
+ (defun mail-get-timezone ()
+   (or mail-timezone
+       (let (gmt-offset sign gmt-time local-time)
+ 	(while (progn
+ 		 (setq local-time (mail-get-time "date"))
+ 		 (setq gmt-time (mail-get-time  "env" "TZ=GMT" "date"))
+ 		 (setq gmt-offset (- local-time gmt-time))
+ 		 (not (= local-time (mail-get-time "date"))))	; minute did not change
+ 	  nil)
+ 	(cond
+ 	 ((< gmt-offset (* -12 60))
+ 	  (setq gmt-offset (+ gmt-offset (* 24 60))))
+ 	 ((> gmt-offset (* 12 60))
+ 	  (setq gmt-offset (- gmt-offset (* 24 60)))))
+ 	(setq sign (< gmt-offset 0))
+ 	(if sign (setq gmt-offset (- gmt-offset)))
+ 	(setq mail-timezone 
+ 	      (concat
+ 		      (if sign "-" "+")
+ 		      (mail-two-digits (/ gmt-offset 60))
+ 		      (mail-two-digits (mod gmt-offset 60))))
+ )))
+ 
  (defun mail-do-fcc (header-end)
    (let (fcc-list
  	(rmailbuf (current-buffer))
  	(tembuf (generate-new-buffer " rmail output"))
  	(case-fold-search t))
      (save-excursion
***************
*** 275,293 ****
  		       (progn (forward-line 1) (point))))
        (set-buffer tembuf)
        (erase-buffer)
-       (call-process "date" nil t nil)
-       (goto-char (point-min))
-       (re-search-forward 
-         "[0-9] \\([A-Za-z][A-Za-z ]*[A-Za-z]\\)[0-9 ]*$")
-       (setq timezone (buffer-substring (match-beginning 1) (match-end 1)))
-       (erase-buffer)
        (insert "\nFrom " (user-login-name) " "
! 	      (current-time-string) "\n")
!       ;; Insert the time zone before the year.
!       (forward-char -1)
        (forward-word -1)
!       (insert timezone " ")
!       (goto-char (point-max))
        (insert-buffer-substring rmailbuf)
        ;; Make sure messages are separated.
        (goto-char (point-max))
--- 323,334 ----
  		       (progn (forward-line 1) (point))))
        (set-buffer tembuf)
        (erase-buffer)
        (insert "\nFrom " (user-login-name) " "
! 	      (current-time-string))
        (forward-word -1)
!       (insert (mail-get-timezone) " ")
!       (forward-word 1)
!       (insert "\n")
        (insert-buffer-substring rmailbuf)
        ;; Make sure messages are separated.
        (goto-char (point-max))
***************
*** 305,315 ****
  	  (if buffer
  	      ;; File is present in a buffer => append to that buffer.
  	      (let ((curbuf (current-buffer))
! 		    (beg (point-min)) (end (point-max)))
  		(save-excursion
  		  (set-buffer buffer)
! 		  (goto-char (point-max))
! 		  (insert-buffer-substring curbuf beg end)))
  	    ;; Else append to the file directly.
  	    (write-region (point-min) (point-max) (car fcc-list) t)))
  	(setq fcc-list (cdr fcc-list))))
--- 346,368 ----
  	  (if buffer
  	      ;; File is present in a buffer => append to that buffer.
  	      (let ((curbuf (current-buffer))
! 		    (curbeg (point-min))
! 		    (curend (point-max)))
  		(save-excursion
  		  (set-buffer buffer)
! 		  (widen)
! 		  (let ((max (point-max))
! 			(buffer-read-only nil))
! 		    (or (verify-visited-file-modtime buffer)
! 			(find-file (car fcc-list)))
! 		    (goto-char max)
! 		    (insert-buffer-substring curbuf curbeg curend)
! 		    (if (eq major-mode 'rmail-mode)
! 			(progn
! 			  (narrow-to-region max (point-max))
! 			  (rmail-convert-to-babyl-format)
! 			  (rmail-set-message-counters)
! 			  (rmail-show-message))))))
  	    ;; Else append to the file directly.
  	    (write-region (point-min) (point-max) (car fcc-list) t)))
  	(setq fcc-list (cdr fcc-list))))
Technical Details
Message-ID: <m0nkwoQ-00039OC@fly.cnuce.cnr.IT>
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!noc.near.net!uunet!wendy-fate.uu.net!bug-vm

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f6829,9793f0ddc38321d4
X-Google-Attributes: gidf6829,public
X-Google-ArrivalTime: 1993-04-19 07:41:14 PST
x-gateway: rodan.UU.NET from bug-vm to gnu.emacs.vm.bug; Mon, 19 Apr 1993 10:34:45 EDT
From: pot@fly.CNUCE.CNR.IT (Francesco Potorti`)
Subject: Problem with timezone in mail header
Reply-To: pot@CNUCE.CNR.IT
Message-ID: <m0nkwoQ-00039OC@fly.cnuce.cnr.IT>
X-Envelope-To: bug-vm@uunet.uu.net
Content-Transfer-Encoding: 7BIT
Date: Mon, 19 Apr 1993 14:34:46 GMT
Newsgroups: gnu.emacs.vm.bug
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!noc.near.net!uunet!wendy-fate.uu.net!bug-vm
Sender: bug-vm-request@uunet.uu.net
Lines: 163