* wl-version.el (wl-generate-user-agent-string-1): New function.
[elisp/wanderlust.git] / wl / wl-version.el
1 ;;; wl-version.el -- Version information for Wanderlust.
2
3 ;; Copyright 2000 Yuuichi Teranishi <teranisi@gohome.org>
4
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7
8 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14 ;;
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19 ;;
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24 ;;
25
26 ;;; Commentary:
27 ;;
28
29 ;;; Code:
30 ;;
31 (require 'product)
32 (provide 'wl-version)                   ; have to declare in the top.
33
34 (product-provide 'wl-version
35   (product-define
36    "Wanderlust" nil
37    (eval-when-compile
38      (require 'elmo-version)
39      (product-version (product-find 'elmo-version))) ; equals to ELMO version.
40    "Roam"))
41
42 ;; set version-string
43 (if (fboundp 'product-version-as-string)
44     (product-version-as-string 'wl-version)
45   (product-string-1 'wl-version))       ; APEL 10.2 or earlier
46
47 ;; require wl-util after product-provide.
48 (eval-when-compile (require 'wl-util))  ; wl-match-string
49
50 ;; compile warning
51 (defvar mule-version)
52 (defvar nemacs-version)
53 (defvar emacs-beta-version)
54 (defvar xemacs-codename)
55 (defvar mime-edit-insert-user-agent-field)
56 (defvar mime-edit-user-agent-value)
57 (defvar mime-editor/version)
58 (defvar mime-editor/codename)
59
60 (defun wl-version (&optional with-codename)
61   "Return Wanderlust version.
62 If WITH-CODENAME add codename."
63   (product-string-1 'wl-version with-codename))
64
65 (defun wl-version-show (&optional arg)
66   "Print Wanderlust version.
67 If ARG insert string at point."
68   (interactive "P")
69   (if arg
70       (insert (message "%s" (wl-version t)))
71     (message "%s" (wl-version t))))
72
73 (defun wl-generate-user-agent-string ()
74   "A candidate of `wl-generate-mailer-string-func'.
75 Insert User-Agent field instead of X-Mailer field."
76   (concat "User-Agent: " (wl-generate-user-agent-string-1 t)))
77
78 (defun wl-generate-user-agent-string-1 (&optional verbose)
79   "Return User-Agent field value."
80   (let ((mime-user-agent (and (boundp 'mime-edit-insert-user-agent-field)
81                               mime-edit-insert-user-agent-field
82                               mime-edit-user-agent-value)))
83     (if (and verbose mime-user-agent)
84         (concat (product-string-verbose 'wl-version) " "
85                 mime-user-agent)
86       (if (and verbose
87                (boundp 'mime-editor/version)
88                mime-editor/version)
89           (concat (product-string-verbose 'wl-version) " "
90                   "tm/" mime-editor/version
91                   (if (and (boundp 'mime-editor/codename)
92                            mime-editor/codename)
93                       (concat " (" mime-editor/codename ")"))
94                   (if (and (boundp 'mime-library-product)
95                            mime-library-product)
96                       (concat " " (aref mime-library-product 0)
97                               "/"
98                               (mapconcat 'int-to-string
99                                          (aref mime-library-product 1)
100                                          ".")
101                               " (" (aref mime-library-product 2) ")"))
102                   (condition-case nil
103                       (progn
104                         (require 'apel-ver)
105                         (concat " " (apel-version)))
106                     (file-error nil))
107                   " " (wl-extended-emacs-version3 "/" t))
108         ;; Don't use product-string-verbose for short User-Agent field.
109         (concat (product-string-1 'wl-version t) " "
110                 (wl-extended-emacs-version3 "/" t))))))
111
112 ;; from gnus
113 (defun wl-extended-emacs-version (&optional with-codename)
114   "Stringified Emacs version.
115 If WITH-CODENAME add XEmacs codename."
116   (cond
117    ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
118     (concat "Emacs " (wl-match-string 1 emacs-version)
119             (and (boundp 'mule-version)(concat "/Mule " mule-version))))
120    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
121                   emacs-version)
122     (concat (wl-match-string 1 emacs-version)
123             (format " %d.%d" emacs-major-version emacs-minor-version)
124             (if (and (boundp 'emacs-beta-version)
125                      emacs-beta-version)
126                 (format "b%d" emacs-beta-version))
127             (if with-codename
128                 (if (boundp 'xemacs-codename)
129                     (concat " - \"" xemacs-codename "\"")))))
130    (t emacs-version)))
131
132 (defun wl-extended-emacs-version2 (&optional delimiter with-codename)
133   "Stringified Emacs version.
134 Separate DELIMITER (default it \" \").  If WITH-CODENAME add XEmacs codename."
135   (cond
136    ((and (boundp 'mule-version)
137          mule-version
138          (string-match "\\([0-9]+\.[0-9]+\\)\\(.*$\\)" mule-version))
139     (format "Mule%s%s@%d.%d%s"
140             (or delimiter " ")
141             (wl-match-string 1 mule-version)
142             emacs-major-version
143             emacs-minor-version
144             (if with-codename
145                 (wl-match-string 2 mule-version)
146               "")))
147    ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
148     (if (boundp 'nemacs-version)
149         (concat "Nemacs" (or delimiter " ")
150                 nemacs-version
151                 "@"
152                 (substring emacs-version
153                            (match-beginning 1)
154                            (match-end 1)))
155       (concat "Emacs" (or delimiter " ")
156               (wl-match-string 1 emacs-version))))
157    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
158                   emacs-version)
159     (concat (wl-match-string 1 emacs-version)
160             (or delimiter " ")
161             (format "%d.%d" emacs-major-version emacs-minor-version)
162             (if (and (boundp 'emacs-beta-version)
163                      emacs-beta-version)
164                 (format "b%d" emacs-beta-version))
165             (if (and with-codename
166                      (boundp 'xemacs-codename)
167                      xemacs-codename)
168                 (format " (%s)" xemacs-codename))))
169    (t emacs-version)))
170
171 (defun wl-extended-emacs-version3 (&optional delimiter with-codename)
172   "Stringified Emacs version.
173 Separate DELIMITER (default it \" \").  If WITH-CODENAME add XEmacs codename."
174   (cond
175    ((and (boundp 'mule-version)
176          mule-version
177          (string-match "\\([0-9]+\.[0-9]+\\)\\(.*$\\)" mule-version))
178     (format "Emacs%s%d.%d Mule%s%s%s"
179             (or delimiter " ")
180             emacs-major-version
181             emacs-minor-version
182             (or delimiter " ")
183             (wl-match-string 1 mule-version)
184             (if with-codename
185                 (wl-match-string 2 mule-version)
186               "")))
187    ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version)
188     (if (boundp 'nemacs-version)
189         (let ((nemacs-codename-assoc '(("3.3.2" . " (FUJIMUSUME)")
190                                        ("3.3.1" . " (HINAMATSURI)")
191                                        ("3.2.3" . " (YUMENO-AWAYUKI)"))))
192           (format "Emacs%s%s Nemacs%s%s%s"
193                   (or delimiter " ")
194                   (wl-match-string 1 emacs-version)
195                   (or delimiter " ")
196                   nemacs-version
197                   (or (and with-codename
198                            (cdr (assoc nemacs-version
199                                        nemacs-codename-assoc)))
200                       "")))
201       (concat "Emacs" (or delimiter " ")
202               (wl-match-string 1 emacs-version))))
203    ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)[^(]*\\(\\((beta.*)\\|'\\)\\)?"
204                   emacs-version)
205     (concat (wl-match-string 1 emacs-version)
206             (or delimiter " ")
207             (format "%d.%d" emacs-major-version emacs-minor-version)
208             (if (and (boundp 'emacs-beta-version)
209                      emacs-beta-version)
210                 (format "b%d" emacs-beta-version))
211             (if (and with-codename
212                      (boundp 'xemacs-codename)
213                      xemacs-codename)
214                 (format " (%s)" xemacs-codename))))
215    (t emacs-version)))
216
217
218 ;; for backward compatibility
219 (defconst wl-appname (product-name (product-find 'wl-version)))
220 (make-obsolete-variable
221  'wl-appname
222  "use (product-name (product-find 'wl-version)) insteaed.")
223
224 (defconst wl-version (product-version-string (product-find 'wl-version)))
225 (make-obsolete-variable
226  'wl-version
227  "use (product-version-string (product-find 'wl-version)) instead.")
228
229 (defconst wl-codename (product-code-name (product-find 'wl-version)))
230 (make-obsolete-variable
231  'wl-codename
232  "use (product-code-name (product-find 'wl-version)) instead.")
233
234 ;;; wl-version.el ends here