Source

xemacsweb / release-mail-to-html.el

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
;;; release-mail-to-html.el --- Convert release mail to HTML for XEmacs
;;;
;;; $Id$
;;;
;;; Copyright (C) 2000 Adrian Aichner

;; Author: Adrian Aichner <adrian@xemacs.org>
;; Maintainer: XEmacs Development Team <xemacs-beta@xemacs.org>
;; Date: $Date$
;; Version: $Revision$
;; Keywords: xemacsweb

;; This file is part of XEmacs.

;; XEmacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; XEmacs is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with XEmacs; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.

;;; Synched up with: Not in FSF.

(condition-case nil
    (progn
      ;; Try to pull in required modules.
      ;; (require 'regexp-opt)
      (require 'psgml)
      (require 'psgml-parse)            ; for sgml-element-context-string
      (require 'psgml-html))            ; for html-quote-region
  (t
   (error "please install/upgrade PSGML!")))


(provide 'release-mail-to-html)

(defgroup release-mail-to-html nil
  "Generate HTML content file for XEmacs website from release
announcement mails as formatted by XEmacs Release Engineer."
  :load 'release-mail-to-html
  :group nil)

(defcustom release-mail-to-html-preformatted-regexp
  "<pre xml:space=\"preserve\">\\(.*?\\(\n.*?\\)*\\)</pre>"
  "REGEXP matching preformatted HTML in the BETA-VERSION.content
buffer generated from beta release mail."
  :type '(regexp
          :custom-show t
          :documentation-shown t)
  :group 'release-mail-to-html)

(defcustom release-mail-headers-to-keep-regexp
  (format "^\\(%s\\)"
          (mapconcat
           'identity
           (list
            "To:"
            "Subject:"
            "From:"
            "Organization:"
            "Date:"
            "Message-ID:"
            "Reply-To:"
            )
           "\\|"))
  "REGEXP matching mail headers to keep from release notice."
  :type '(regexp
          :custom-show t
          :documentation-shown t)
  :group 'release-mail-to-html)

(defcustom release-mail-to-html-header-regexp
  "^\\(\\(-\\|\\sw\\)+\\)\\s-*:\\s-*\\(.*\\(\n\\s-+.*\\)*\\)\n"
  "REGEXP matching mail headers."
  :type '(regexp
          :custom-show t
          :documentation-shown t)
  :group 'release-mail-to-html)

(defcustom release-mail-to-html-subject-regexp
  "^subject\\s-*:\\s-*XEmacs\\s-+\\([0-9]+\\)\\.\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\|\\s-+(patch\\s-+\\([0-9]+\\))\\)\\s-+\\(\\(\"[^\"]+\"\\)\\s-+\\)?\\(is\\|has\\s-+been\\)\\s-+released"
  "REGEXP matching mail subject header in an XEmacs beta release mail,
returning release number as match-string 1."
  :type '(regexp
          :custom-show t
          :documentation-shown t)
  :group 'release-mail-to-html)

(defcustom release-mail-to-html-summary-header-regexp
  "^.*Brief\\s-+summary\\s-+of\\s-+changes\\s-+to\\s-+\\(\\S-+\\)\\s-+\\(\"[^\"]+\"\\)\n*"
  "REGEXP matching the brief summary header of changes in an XEmacs
beta release mail."
  :type '(regexp
          :custom-show t
          :documentation-shown t)
  :group 'release-mail-to-html)

(defcustom release-mail-to-html-summary-item-regexp
  "^-- \\(.*\\(\n\\s-+.*\\)*\\)\n*"
  "REGEXP matching a single change in the brief summary of changes in
an XEmacs beta release mail."
  :type '(regexp
          :custom-show t
          :documentation-shown t)
  :group 'release-mail-to-html)

(defcustom release-mail-to-html-changelog-record-regexp
  "\n*[0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\s-+\\(?:.*\\)\\s-+\\(?:<[^>]+>\\)\\(\n*\\s-+.*\\)+\n*"
  "REGEXP matching one ChangeLog record for a (sub-)directory in an
XEmacs beta release mail."
  :type '(regexp
          :custom-show t
          :documentation-shown t)
  :group 'release-mail-to-html)

(defcustom release-mail-to-html-changelog-regexp
  (format "\n*-+\\s-*ChangeLog\\s-+entries\\s-+from\\s-+[^/]+/\\(.*ChangeLog\\)\\s-*-+\\(\\(%s\\)+\\)\n*" release-mail-to-html-changelog-record-regexp)
  "REGEXP matching all ChangeLog records for a sub-directory in an
XEmacs beta release mail."
  :type '(regexp
          :custom-show t
          :documentation-shown t)
  :group 'release-mail-to-html)

(defcustom release-mail-to-html-patch-regexp
  "^\\s-*From:\\s-*\\(.*\\)\\s-*\nSubject:\\s-*\\(.*\\)\\s-*\n\\S-*URL:\\s-*\\(.*\\)\\s-*$"
  "REGEXP matching patch records in an XEmacs beta release mail."
  :type '(regexp
          :custom-show t
          :documentation-shown t)
  :group 'release-mail-to-html)

(defun release-mail-to-html (&optional buffer)
  "Create HTML from XEmacs release mail."
  (interactive
   (list
    (read-buffer "buffer containing release mail: " "*Article*" t)))
  (save-excursion
    (with-temp-buffer
      (insert-buffer buffer)
      (modify-syntax-entry ?\n ">   " (syntax-table))
      (let (major-version
            minor-version
            beta-version
            xemacs-version
            code-name
            release-mail-summary-items
            release-mail-to-html-changelog-alist
            release-mail-to-html-patch-list
            release-mail-announcement
            release-mail-index)
        (goto-char (point-min))
        ;; Extract version information from subject line.
        (when (re-search-forward
               release-mail-to-html-subject-regexp nil t)
          (setq major-version
                (match-string 1)
                minor-version
                (match-string 2)
                beta-version
                (or
                 (match-string 4)
                 (match-string 5))
                code-name
                (match-string 7)
                )
          (and
           major-version
           minor-version
           beta-version
           (setq xemacs-version
                 (format
                  "%s.%s.%s"
                  major-version minor-version beta-version))))
        ;; Extract summary items from announcement body.
        (when (re-search-forward
               release-mail-to-html-summary-header-regexp nil t)
          (or xemacs-version
              (setq xemacs-version
                    (match-string 1)))
          (or code-name
              (setq
               code-name
               (match-string 2)))
          (delete-region
           (match-beginning 0)
           (match-end 0))
          (while (re-search-forward
                  release-mail-to-html-summary-item-regexp nil t)
            (setq release-mail-summary-items
                  (append release-mail-summary-items (list (match-string 1))))
            (delete-region
             (match-beginning 0)
             (match-end 0))))
        ;; Extract changelog entries from announcement body.
        (while (re-search-forward
                release-mail-to-html-changelog-regexp nil t)
          (setq release-mail-to-html-changelog-alist
                (append
                 release-mail-to-html-changelog-alist
                 (list
                  (cons
                   (match-string 1)
                   (match-string 2)))))
          (delete-region
           (match-beginning 0)
           (match-end 0)))
        ;; Extract applied patches from announcement body.
        (while (re-search-forward
                release-mail-to-html-patch-regexp nil t)
          (setq release-mail-to-html-patch-list
                (append
                 release-mail-to-html-patch-list
                 (list
                  (list
                   (match-string 1)
                   (match-string 2)
                   (match-string 3)))))
          (delete-region
           (match-beginning 0)
           (match-end 0)))
        ;; Get remaining free-form announcement body.
        (goto-char (point-min))
        (re-search-forward "\n\n" nil t)
        ;; Process mail header.
        (save-restriction
          (narrow-to-region
           (point-min)
           (- (point) 1))
          (goto-char (point-min))
          (delete-non-matching-lines
           release-mail-headers-to-keep-regexp))
        (setq release-mail-announcement
              (buffer-substring
               (point-min)
               (point-max)))
        ;; Generate list of index items
        (when release-mail-to-html-patch-list
          (setq
           release-mail-index
           (cons "patches" release-mail-index)))
        (when release-mail-to-html-changelog-alist
          (setq
           release-mail-index
           (cons "changes" release-mail-index)))
        (when release-mail-announcement
          (setq
           release-mail-index
           (cons "announcement" release-mail-index)))
        (when release-mail-summary-items
          (setq
           release-mail-index
           (cons "summary" release-mail-index)))
        ;; Generate XML/XHTML/HTML document.
        (with-output-to-temp-buffer
            (format "%s.content" xemacs-version)
          (progn
            (princ
             (format "%%title%%
XEmacs %s %s is Released
%%author%%
automatically generated from release announcement by release-mail-to-html.el
%%main%%
"
                     xemacs-version
                     code-name))
            (when release-mail-announcement
              (princ
               (format
                "            <h1><a name=\"announcement\" shape=\"rect\">XEmacs</a> %s %s is Released</h1>\n"
                xemacs-version code-name))
              (princ
               (release-mail-index release-mail-index))
              (princ
               (format
                "<pre xml:space=\"preserve\">\n%s</pre>\n"
                release-mail-announcement)))
            (when (and xemacs-version code-name release-mail-summary-items)
              (princ
               (format
                "            <h1><a name=\"summary\" shape=\"rect\">Changes</a> in XEmacs %s %s</h1>\n"
                xemacs-version code-name))
              (princ
               (release-mail-index release-mail-index))
              (princ "            <ul>\n")
              (mapc
               (function
                (lambda (c)
                  (princ (format "	    <li>%s</li>\n" c))))
               release-mail-summary-items)
              (princ "	  </ul>\n"))
            (when (and
                   xemacs-version
                   code-name
                   release-mail-to-html-changelog-alist)
              (princ
               (format
                "            <h1><a name=\"changes\" shape=\"rect\">ChangeLogs</a> for XEmacs %s %s</h1>\n"
                xemacs-version code-name))
              (princ
               (release-mail-index release-mail-index))
              (princ
               (format
                "            <ul>\n"))
              (mapc
               (function
                (lambda (l)
                  (princ
                   (format
                    "	    <li>ChangeLog Entries from <a href=\"#%s\" shape=\"rect\">%s</a></li>\n"
                    (replace-in-string (car l) "/" ":")
                    (car l)))))
               release-mail-to-html-changelog-alist)
              (princ
               "	  </ul>\n")
              (mapc
               (function
                (lambda (l)
                  (princ
                   (format
                    "            <h1>ChangeLog Entries from <a name=\"%s\" shape=\"rect\">%s</a></h1>\n%s            <pre xml:space=\"preserve\">%s</pre>\n"
                    (replace-in-string (car l) "/" ":")
                    (car l)
                    (release-mail-index release-mail-index)
                    (cdr l)))))
               release-mail-to-html-changelog-alist))
            (when release-mail-to-html-patch-list
              (princ
               (format "            <h1><a name=\"patches\" shape=\"rect\">Patches</a> in XEmacs %s %s</h1>\n"
                       xemacs-version code-name))
              (princ
               (release-mail-index release-mail-index))
              (princ "          <table border=\"0\">\n")
              (princ "            <tr>\n")
              (princ "            <td>\n")
              (princ "          <table width=\"100%\" border=\"1\">\n")
              (princ "            <tr>\n")
              (princ "              <th width=\"20%\" rowspan=\"1\" colspan=\"1\">Author</th>\n")
              (princ "              <th rowspan=\"1\" colspan=\"1\">Subject</th>\n")
              (princ "            </tr>\n")
              (princ "            <tr>\n")
              (princ "              <th rowspan=\"1\" colspan=\"2\">Patch URL</th>\n")
              (princ "            </tr>\n")
              (princ "          </table>\n")
              (princ "            </td>\n")
              (princ "            </tr>\n")
              (mapc
               (function
                (lambda (c)
                  (princ "            <tr>\n")
                  (princ "            <td rowspan=\"1\" colspan=\"1\">\n")
                  (princ "          <table width=\"100%\" border=\"1\">\n")
                  (princ "            <tr>\n")
                  (princ
                   (format "              <td width=\"20%%\" rowspan=\"1\" colspan=\"1\">%s</td>\n"
                           (release-mail-markup-author
                            (first c))))
                  (princ
                   (format "              <td rowspan=\"1\" colspan=\"1\">%s</td>\n"
                           (release-mail-markup-subject (second c))))
                  (princ "            </tr>\n")
                  (princ "            <tr>\n")
                  (princ
                   (format "              <td rowspan=\"1\" colspan=\"2\">%s</td>\n"
                           (release-mail-markup-url
                            (third c))))
                  (princ "            </tr>\n")
                  (princ "          </table>\n")
                  (princ "            </td>\n")
                  (princ "            </tr>\n")
                  ))
               release-mail-to-html-patch-list)
              (princ "          </table>\n"))
            (princ
             (release-mail-index release-mail-index))
            ));; Quote HTML markup in preformatted sections.
        (with-current-buffer
            (get-buffer
             (format "%s.content" xemacs-version))
          (goto-char (point-min))
          (while (re-search-forward
                  release-mail-to-html-preformatted-regexp
                  nil t)
            (html-quote-region
             (match-beginning 1)
             (match-end 1))))))))

(defun release-mail-markup-author (author)
  (let
      ((components
        (mail-extract-address-components author)))
    (with-temp-buffer
      (insert
       (or
        (first components)
        (second components)))
      (html-quote-region
       (point-min)
       (point-max))
      (goto-char (point-min))
      (insert
       (format
        "<a href=\"mailto:%s\">"
        (second components)))
      (goto-char (point-max))
      (insert (format "</a>"))
      (buffer-string))))

(defun release-mail-markup-url (url)
  (if
      (string-match
       "\\`\\(http\\|ftp\\)://" url)
      (format
       "<a href=\"%s\">%s</a>"
       url url)
    url))

(defun release-mail-markup-subject (subject)
  (with-temp-buffer
    (insert subject)
    (html-quote-region
     (point-min)
     (point-max))
    (goto-char (point-min))
    (insert "<strong>")
    (goto-char (point-max))
    (insert "</strong>")
    (buffer-string)))

(defun release-mail-index (items)
  (when items
    (with-temp-buffer
      (insert "            <p>goto ")
      (mapc
       (function
        (lambda (i)
          (insert (format "<a href=\"#%s\" shape=\"rect\">%s</a>\n" i i))))
       items)
      (insert "</p>\n")
      (goto-char (point-min))
      (replace-regexp "</a>\n<a" "</a>,\n<a")
      (buffer-string))))

;;; release-mail-to-html.el ends here