diff options
| author | Katsumi Yamaoka | 2014-04-15 23:37:21 +0000 |
|---|---|---|
| committer | Katsumi Yamaoka | 2014-04-15 23:37:21 +0000 |
| commit | 07abb6e4c13a7246b74cfc5b77d46495dcfaefd4 (patch) | |
| tree | 72f6019108cf9bc1ca6d7b27c80c66b7773bd4c5 | |
| parent | 005551fe3654f6037f78921388302fb2929c459e (diff) | |
| download | emacs-07abb6e4c13a7246b74cfc5b77d46495dcfaefd4.tar.gz emacs-07abb6e4c13a7246b74cfc5b77d46495dcfaefd4.zip | |
lisp/gnus/message.el (message-insert-formatted-citation-line): Use the original author's time zone to express a date string
| -rw-r--r-- | lisp/gnus/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/gnus/gmm-utils.el | 32 | ||||
| -rw-r--r-- | lisp/gnus/message.el | 74 |
3 files changed, 87 insertions, 26 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index 17bbff732b6..41ad2875691 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2014-04-15 Katsumi Yamaoka <yamaoka@jpl.org> | ||
| 2 | |||
| 3 | * gmm-utils.el (gmm-format-time-string): New function. | ||
| 4 | |||
| 5 | * message.el (message-insert-formatted-citation-line): Use the original | ||
| 6 | author's time zone to express a date string. | ||
| 7 | |||
| 1 | 2014-04-06 Stefan Monnier <monnier@iro.umontreal.ca> | 8 | 2014-04-06 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 9 | ||
| 3 | * gnus-srvr.el (gnus-tmp-how, gnus-tmp-name, gnus-tmp-where) | 10 | * gnus-srvr.el (gnus-tmp-how, gnus-tmp-name, gnus-tmp-where) |
diff --git a/lisp/gnus/gmm-utils.el b/lisp/gnus/gmm-utils.el index 63947e5f486..70ef27a7e90 100644 --- a/lisp/gnus/gmm-utils.el +++ b/lisp/gnus/gmm-utils.el | |||
| @@ -443,6 +443,38 @@ rather than relying on `lexical-binding'. | |||
| 443 | (put 'gmm-labels 'lisp-indent-function 1) | 443 | (put 'gmm-labels 'lisp-indent-function 1) |
| 444 | (put 'gmm-labels 'edebug-form-spec '((&rest (sexp sexp &rest form)) &rest form)) | 444 | (put 'gmm-labels 'edebug-form-spec '((&rest (sexp sexp &rest form)) &rest form)) |
| 445 | 445 | ||
| 446 | (defun gmm-format-time-string (format-string &optional time tz) | ||
| 447 | "Use FORMAT-STRING to format the time TIME, or now if omitted. | ||
| 448 | The optional TZ specifies the time zone in a number of seconds; any | ||
| 449 | other non-nil value will be treated as 0. Note that both the format | ||
| 450 | specifiers `%Z' and `%z' will be replaced with a numeric form. " | ||
| 451 | ;; FIXME: is there a smart way to replace %Z with a time zone name? | ||
| 452 | (if (and (numberp tz) (not (zerop tz))) | ||
| 453 | (let ((st 0) | ||
| 454 | (case-fold-search t) | ||
| 455 | ls nd rest) | ||
| 456 | (setq time (if time | ||
| 457 | (copy-sequence time) | ||
| 458 | (current-time))) | ||
| 459 | (if (>= (setq ls (- (cadr time) (car (current-time-zone)) (- tz))) 0) | ||
| 460 | (setcar (cdr time) ls) | ||
| 461 | (setcar (cdr time) (+ ls 65536)) | ||
| 462 | (setcar time (1- (car time)))) | ||
| 463 | (setq tz (format "%s%02d%02d" | ||
| 464 | (if (>= tz 0) "+" "-") | ||
| 465 | (/ (abs tz) 3600) | ||
| 466 | (/ (% (abs tz) 3600) 60))) | ||
| 467 | (while (string-match "%+z" format-string st) | ||
| 468 | (if (zerop (% (- (setq nd (match-end 0)) (match-beginning 0)) 2)) | ||
| 469 | (progn | ||
| 470 | (push (substring format-string st (- nd 2)) rest) | ||
| 471 | (push tz rest)) | ||
| 472 | (push (substring format-string st nd) rest)) | ||
| 473 | (setq st nd)) | ||
| 474 | (push (substring format-string st) rest) | ||
| 475 | (format-time-string (apply 'concat (nreverse rest)) time)) | ||
| 476 | (format-time-string format-string time tz))) | ||
| 477 | |||
| 446 | (provide 'gmm-utils) | 478 | (provide 'gmm-utils) |
| 447 | 479 | ||
| 448 | ;;; gmm-utils.el ends here | 480 | ;;; gmm-utils.el ends here |
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el index 1f42ccb61f4..ca0280c874f 100644 --- a/lisp/gnus/message.el +++ b/lisp/gnus/message.el | |||
| @@ -982,8 +982,8 @@ configuration. See the variable `gnus-cite-attribution-suffix'." | |||
| 982 | (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n" | 982 | (defcustom message-citation-line-format "On %a, %b %d %Y, %N wrote:\n" |
| 983 | "Format of the \"Whomever writes:\" line. | 983 | "Format of the \"Whomever writes:\" line. |
| 984 | 984 | ||
| 985 | The string is formatted using `format-spec'. The following | 985 | The string is formatted using `format-spec'. The following constructs |
| 986 | constructs are replaced: | 986 | are replaced: |
| 987 | 987 | ||
| 988 | %f The full From, e.g. \"John Doe <john.doe@example.invalid>\". | 988 | %f The full From, e.g. \"John Doe <john.doe@example.invalid>\". |
| 989 | %n The mail address, e.g. \"john.doe@example.invalid\". | 989 | %n The mail address, e.g. \"john.doe@example.invalid\". |
| @@ -991,11 +991,14 @@ constructs are replaced: | |||
| 991 | back to the mail address. | 991 | back to the mail address. |
| 992 | %F The first name if present, e.g.: \"John\". | 992 | %F The first name if present, e.g.: \"John\". |
| 993 | %L The last name if present, e.g.: \"Doe\". | 993 | %L The last name if present, e.g.: \"Doe\". |
| 994 | %Z, %z The time zone in the numeric form, e.g.:\"+0000\". | ||
| 994 | 995 | ||
| 995 | All other format specifiers are passed to `format-time-string' | 996 | All other format specifiers are passed to `format-time-string' |
| 996 | which is called using the date from the article your replying to. | 997 | which is called using the date from the article your replying to, but |
| 997 | Extracting the first (%F) and last name (%L) is done | 998 | the date in the formatted string will be expressed in the author's |
| 998 | heuristically, so you should always check it yourself. | 999 | time zone as much as possible. |
| 1000 | Extracting the first (%F) and last name (%L) is done heuristically, | ||
| 1001 | so you should always check it yourself. | ||
| 999 | 1002 | ||
| 1000 | Please also read the note in the documentation of | 1003 | Please also read the note in the documentation of |
| 1001 | `message-citation-line-function'." | 1004 | `message-citation-line-function'." |
| @@ -3920,9 +3923,13 @@ This function uses `mail-citation-hook' if that is non-nil." | |||
| 3920 | (defvar gnus-extract-address-components) | 3923 | (defvar gnus-extract-address-components) |
| 3921 | 3924 | ||
| 3922 | (autoload 'format-spec "format-spec") | 3925 | (autoload 'format-spec "format-spec") |
| 3926 | (autoload 'gnus-date-get-time "gnus-util") | ||
| 3923 | 3927 | ||
| 3924 | (defun message-insert-formatted-citation-line (&optional from date) | 3928 | (defun message-insert-formatted-citation-line (&optional from date tz) |
| 3925 | "Function that inserts a formatted citation line. | 3929 | "Function that inserts a formatted citation line. |
| 3930 | The optional FROM, and DATE are strings containing the contents of | ||
| 3931 | the From header and the Date header respectively. The optional TZ | ||
| 3932 | is a number of seconds, overrides the time zone of DATE. | ||
| 3926 | 3933 | ||
| 3927 | See `message-citation-line-format'." | 3934 | See `message-citation-line-format'." |
| 3928 | ;; The optional args are for testing/debugging. They will disappear later. | 3935 | ;; The optional args are for testing/debugging. They will disappear later. |
| @@ -3930,7 +3937,7 @@ See `message-citation-line-format'." | |||
| 3930 | ;; (with-temp-buffer | 3937 | ;; (with-temp-buffer |
| 3931 | ;; (message-insert-formatted-citation-line | 3938 | ;; (message-insert-formatted-citation-line |
| 3932 | ;; "John Doe <john.doe@example.invalid>" | 3939 | ;; "John Doe <john.doe@example.invalid>" |
| 3933 | ;; (current-time)) | 3940 | ;; (message-make-date)) |
| 3934 | ;; (buffer-string)) | 3941 | ;; (buffer-string)) |
| 3935 | (when (or message-reply-headers (and from date)) | 3942 | (when (or message-reply-headers (and from date)) |
| 3936 | (unless from | 3943 | (unless from |
| @@ -3947,28 +3954,43 @@ See `message-citation-line-format'." | |||
| 3947 | (net (car (cdr data))) | 3954 | (net (car (cdr data))) |
| 3948 | (name-or-net (or (car data) | 3955 | (name-or-net (or (car data) |
| 3949 | (car (cdr data)) from)) | 3956 | (car (cdr data)) from)) |
| 3950 | (replydate | 3957 | (time |
| 3951 | (or | 3958 | (when (string-match "%[^fnNFL]" message-citation-line-format) |
| 3952 | date | 3959 | (cond ((numberp (car-safe date)) date) ;; backward compatibility |
| 3953 | ;; We need Gnus functionality if the user wants date or time from | 3960 | (date (gnus-date-get-time date)) |
| 3954 | ;; the original article: | 3961 | (t |
| 3955 | (when (string-match "%[^fnNFL]" message-citation-line-format) | 3962 | (gnus-date-get-time |
| 3956 | (autoload 'gnus-date-get-time "gnus-util") | 3963 | (setq date (mail-header-date message-reply-headers))))))) |
| 3957 | (gnus-date-get-time (mail-header-date message-reply-headers))))) | 3964 | (tz (or tz |
| 3965 | (when (stringp date) | ||
| 3966 | (nth 8 (parse-time-string date))))) | ||
| 3958 | (flist | 3967 | (flist |
| 3959 | (let ((i ?A) lst) | 3968 | (let ((i ?A) lst) |
| 3960 | (when (stringp name) | 3969 | (when (stringp name) |
| 3961 | ;; Guess first name and last name: | 3970 | ;; Guess first name and last name: |
| 3962 | (let* ((names (delq nil (mapcar (lambda (x) | 3971 | (let* ((names (delq |
| 3963 | (if (string-match "\\`\\(\\w\\|[-.]\\)+\\'" x) x nil)) | 3972 | nil |
| 3964 | (split-string name "[ \t]+")))) | 3973 | (mapcar |
| 3965 | (count (length names))) | 3974 | (lambda (x) |
| 3966 | (cond ((= count 1) (setq fname (car names) | 3975 | (if (string-match "\\`\\(\\w\\|[-.]\\)+\\'" |
| 3967 | lname "")) | 3976 | x) |
| 3968 | ((or (= count 2) (= count 3)) (setq fname (car names) | 3977 | x |
| 3969 | lname (mapconcat 'identity (cdr names) " "))) | 3978 | nil)) |
| 3970 | ((> count 3) (setq fname (mapconcat 'identity (butlast names (- count 2)) " ") | 3979 | (split-string name "[ \t]+")))) |
| 3971 | lname (mapconcat 'identity (nthcdr 2 names) " "))) ) | 3980 | (count (length names))) |
| 3981 | (cond ((= count 1) | ||
| 3982 | (setq fname (car names) | ||
| 3983 | lname "")) | ||
| 3984 | ((or (= count 2) (= count 3)) | ||
| 3985 | (setq fname (car names) | ||
| 3986 | lname (mapconcat 'identity (cdr names) " "))) | ||
| 3987 | ((> count 3) | ||
| 3988 | (setq fname (mapconcat 'identity | ||
| 3989 | (butlast names (- count 2)) | ||
| 3990 | " ") | ||
| 3991 | lname (mapconcat 'identity | ||
| 3992 | (nthcdr 2 names) | ||
| 3993 | " ")))) | ||
| 3972 | (when (string-match "\\(.*\\),\\'" fname) | 3994 | (when (string-match "\\(.*\\),\\'" fname) |
| 3973 | (let ((newlname (match-string 1 fname))) | 3995 | (let ((newlname (match-string 1 fname))) |
| 3974 | (setq fname lname lname newlname))))) | 3996 | (setq fname lname lname newlname))))) |
| @@ -3998,7 +4020,7 @@ See `message-citation-line-format'." | |||
| 3998 | (>= i ?a))) | 4020 | (>= i ?a))) |
| 3999 | (push i lst) | 4021 | (push i lst) |
| 4000 | (push (condition-case nil | 4022 | (push (condition-case nil |
| 4001 | (format-time-string (format "%%%c" i) replydate) | 4023 | (gmm-format-time-string (format "%%%c" i) time tz) |
| 4002 | (error (format ">%c<" i))) | 4024 | (error (format ">%c<" i))) |
| 4003 | lst)) | 4025 | lst)) |
| 4004 | (setq i (1+ i))) | 4026 | (setq i (1+ i))) |