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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
;;; 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
      ;; 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-mail-buffer-name "*Article*"
  "Name of buffer containing software release mail announcement of any
  type defined in `release-mail-to-html-regexp-alist'."
  :type 'string
  :group 'release-mail-to-html)

(setq release-mail-to-html-regexp-alist
      (list
       (list
	"XEmacs"
	'release-mail-to-html-preformatted-regexp
	(list
	 "<pre xml:space=\"preserve\">\\(.*?\\(\n.*?\\)*\\)</pre>" :body 1)
	'release-mail-to-html-headers-to-keep-regexp
	(list
	 (format "^\\(%s\\)"
		 (mapconcat
		  'identity
		  (list
		   "To:"
		   "Subject:"
		   "From:"
		   "Organization:"
		   "Date:"
		   "Message-ID:"
		   "Reply-To:"
		   )
		  "\\|")) :header-name 1)
	'release-mail-to-html-header-regexp
	(list
	 "^\\(\\(-\\|\\sw\\)+\\)[ \t]*:[ \t]*\\(.*\\(\n[ \t]+.*\\)*\\)\n")
	'release-mail-to-html-body-separator-regexp
	(list
	 "\n\\(--text follows this line--\\)?\n")
	'release-mail-to-html-subject-regexp
	(list
	 "^subject[ \t]*:[ \t]*\\(?:\\[ANNOUNCE\\][ \t]*\\)?\\(XEmacs\\)[- \t]+\\([0-9]+\\)\\.\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\|[ \t]+(patch[ \t]+\\([0-9]+\\))\\)[ \t]+\\(\\(\"[^\"]+\"\\)[ \t]+\\)?\\(is\\|has[ \t]+been\\)[ \t]+\\(announced\\|released\\)"
	 :type 1 :major 2 :minor 3 :beta 5 :patch 6 :code-name 8)
	'release-mail-to-html-summary-header-regexp
	(list
	 "^.*Brief[ \t]+summary[ \t]+of[ \t]+changes[ \t]+to\\(?:[ \t]+XEmacs\\)?[ \t]+\\([^ \t]+\\)[ \t]+\\(\"[^\"]+\"\\)\n*"
	 :version-name 1 :code-name 2)
	'release-mail-to-html-summary-name-regexp
	(list
	 "\\=\\([^-].+\\)\n+" :summary-name 1)
	'release-mail-to-html-summary-item-regexp
	(list
	 "\\=-- \\(.+\\(\n[ \t]+.*\\)*\\)\n*" :summary-item 1)
	'release-mail-to-html-changelog-record-regexp
	(list
	 "\\=\n+\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)[ \t]+\\(.+?\\)\\(?:  \\(<[^>]+>\\)\\)?\\(\n+[ \t]+.*\\)+"
	 :record 0 :date 1 :author 2 :email-address 3 :body 4)
	'release-mail-to-html-changelog-regexp
	(list
	 "\n*-+[ \t]*ChangeLog[ \t]+entries[ \t]+from[ \t]+\\(.*\\)[ \t]+-+"
	 :change-log-name 1)
	'release-mail-to-html-patch-regexp
	(list
	 "^From:[ \t]*\\(.*\\)[ \t]*\nSubject:[ \t]*\\(.*\\)[ \t]*\n\\(.+\\)[ \t>]*\n+"
	 :from 1 :subject 2 :reference 3)
	)
       (list
	"XEmacs Packages"
	'release-mail-to-html-preformatted-regexp
	(list
	 "<pre xml:space=\"preserve\">\\(.*?\\(\n.*?\\)*\\)</pre>" :body 1)
	'release-mail-to-html-headers-to-keep-regexp
	(list
	 (format "^\\(%s\\)"
		 (mapconcat
		  'identity
		  (list
		   "To:"
		   "Subject:"
		   "From:"
		   "Organization:"
		   "Date:"
		   "Message-ID:"
		   "Reply-To:"
		   )
		  "\\|")) :header-name 1)
	'release-mail-to-html-header-regexp
	(list
	 "^\\(\\(-\\|\\sw\\)+\\)[ \t]*:[ \t]*\\(.*\\(\n[ \t]+.*\\)*\\)\n")
	'release-mail-to-html-body-separator-regexp
	(list
	 "\n\\(--text follows this line--\\)?\n")
	'release-mail-to-html-subject-regexp
	(list
	 "^subject[ \t]*:[ \t]*\\(?:\\[ANNOUNCE\\][ \t]*\\)?\\(XEmacs Packages\\) have been \\(?:pre-\\)?released (\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\(?:-[0-9]\\{2\\}\\)?\\))"
	 :type 1 :code-name 2)
	'release-mail-to-html-summary-header-regexp
	(list
	 "^.*Brief[ \t]+summary[ \t]+of[ \t]+changes[ \t]+to\\(?:[ \t]+XEmacs\\)?[ \t]+\\([^ \t]+\\)[ \t]+\\(\"[^\"]+\"\\)\n*" :version-name 1 :code-name 2)
	'release-mail-to-html-summary-name-regexp
	(list
	 "\\=\\([^-].+\\)\n+" :summary-name 1)
	'release-mail-to-html-summary-item-regexp
	(list
	 "\\=-- \\(.+\\(\n[ \t]+.*\\)*\\)\n*" :summary-item 1)
	'release-mail-to-html-changelog-record-regexp
	(list
	 "\\=\n+\\([0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}\\)[ \t]+\\(.+?\\)\\(?:  \\(<[^>]+>\\)\\)?\\(\n+[ \t]+.*\\)+"
	 :record 0 :date 1 :author 2 :email-address 3 :body 4)
	'release-mail-to-html-changelog-regexp
	(list
	 "\n*-+[ \t]*ChangeLog[ \t]+entries[ \t]+from[ \t]+\\(.*\\)[ \t]+-+"
	 :change-log-name 1)
	'release-mail-to-html-patch-regexp
	(list
	 "^From:[ \t]*\\(.*\\)[ \t]*\nSubject:[ \t]*\\(.*\\)[ \t]*\n\\(.+\\)[ \t>]*\n+"))))

(defun release-mail-to-html (&optional buffer type)
  "*Create HTML from XEmacs release announcement mail.
BUFFER (defaulting to *Article*) needs to hold a standard release
announcement for a stable or beta release of XEmacs, as mailed to
<xemacs-announce@xemacs.org> or <xemacs-beta@xemacs.org> respectively.
The HTML output is placed in a buffer named uniquely (see
`generate-new-buffer-name'), based on the format
MAJOR.MINOR.PATCH.content, where PATCH may be a BETA number instead.
This is the standard filename used as genpage input to create the
corresponding HTML file.  The actual name used for buffer is returned.

Expected Release Announcement Format:

MAIL-HEADER+
FREE-FORM-TEXT*
SUMMARY-OF-CHANGES*
CHANGELOG-ENTRIES*
LIST-OF-APPLIED-PATCHES*
FREE-FORM-TEXT*

The relevant sections are matches according to these regular expression:

`release-mail-to-html-subject-regexp'
`release-mail-to-html-summary-header-regexp'
`release-mail-to-html-summary-name-regexp'
`release-mail-to-html-summary-item-regexp'
`release-mail-to-html-changelog-regexp'
`release-mail-to-html-changelog-record-regexp'
`release-mail-to-html-patch-regexp'
"
  (interactive
   (list
    (read-buffer "buffer containing release mail: "
		 release-mail-to-html-mail-buffer-name t)))
  (let (result
	major-version
	minor-version
	patch-level
	xemacs-version-from-subject
	code-name-from-subject
	subject)
    (with-current-buffer
	buffer
      (mapc
       (function
	(lambda (type-entry)
	  (setq result
		(release-mail-to-html-match
		 'release-mail-to-html-subject-regexp
		 'point-min
		 nil
		 type-entry))
	  (when result
	    (setq major-version (plist-get result :major)
		  minor-version (plist-get result :minor)
		  patch-level (or 
			       (plist-get result :patch)
			       (plist-get result :beta))
		  code-name-from-subject (plist-get result :code-name)
		  subject (let ((raw-subject (match-string 0)))
			    (when (string-match "^subject: " raw-subject)
			      (replace-match "" t nil raw-subject))))
	      (setq type (plist-get result :type)))))
       release-mail-to-html-regexp-alist))
    (when type
      (save-excursion
	(with-temp-buffer
	  (insert-buffer buffer)
	  (let
	      (xemacs-version-from-summary
	       code-name-from-summary
	       release-mail-to-html-summary-alist
	       release-mail-to-html-changelog-alist
	       release-mail-to-html-patch-list
	       release-mail-announcement
	       release-mail-index
	       content-buffer
	       (case-fold-search t))
	    (goto-char (point-min))
	    ;; Extract version information from subject line:
	    (and
	     major-version minor-version patch-level
	     (setq xemacs-version-from-subject
		   (format
		    "%s.%s.%s" major-version minor-version patch-level)))
	    ;; Extract version information from brief summary of changes
	    ;; heading:
	    (release-mail-to-html-match
	     'release-mail-to-html-body-separator-regexp
	     'point-min
	     nil
	     (assoc type release-mail-to-html-regexp-alist))
	    (when
		(setq result
		      (release-mail-to-html-match
		       'release-mail-to-html-summary-header-regexp
		       nil
		       nil
		       (assoc type release-mail-to-html-regexp-alist)))
	      (setq xemacs-version-from-summary 
		    (plist-get result :version-name 1))
	      (if (= (length xemacs-version-from-summary) 0)
		  (error
		   "release-mail-to-html: version is empty as matched by %S."
		   'release-mail-to-html-summary-header-regexp))
	      (setq
	       code-name-from-summary (plist-get result :code-name))
	      (if (= (length code-name-from-summary) 0)
		  (error
		   "release-mail-to-html: codename is empty as matched by %S."
		   'release-mail-to-html-summary-header-regexp))
	      (unless
		  (string=
		   xemacs-version-from-summary
		   xemacs-version-from-subject)
		(warn
		 "release-mail-to-html: %s specifies different XEmacs versions as matched by %S and %S."
		 buffer
		 'release-mail-to-html-summary-header-regexp
		 'release-mail-to-html-subject-regexp))
	      (unless (string=
		       code-name-from-summary code-name-from-subject)
		(warn
		 "release-mail-to-html: %s specifies different XEmacs codenames as matched by %S and %S."
		 buffer
		 'release-mail-to-html-summary-header-regexp
		 'release-mail-to-html-subject-regexp))
	      ;; Extract summary entries from announcement body.
	      (let (summary-name
		    summary-items)
		(release-mail-to-html-match
		 'release-mail-to-html-summary-header-regexp
		 'point-min
		 'delete
		 (assoc type release-mail-to-html-regexp-alist))
		(while
		    (setq result
			  (release-mail-to-html-match
			   'release-mail-to-html-summary-name-regexp
			   nil
			   'delete
			   (assoc type release-mail-to-html-regexp-alist)))
		  (setq summary-name (plist-get result :summary-name))
		  (while
		      (setq result
			    (release-mail-to-html-match
			     'release-mail-to-html-summary-item-regexp
			     nil
			     'delete
			     (assoc type release-mail-to-html-regexp-alist)))
		    (setq summary-items
			  (append summary-items
				  (list (plist-get result :summary-item)))))
		  (setq release-mail-to-html-summary-alist
			(append
			 release-mail-to-html-summary-alist
			 (list
			  (cons
			   summary-name summary-items))))
		  (setq summary-name nil summary-items nil))))
	    ;; Extract changelog entries from announcement body.
	    (let (changelog-name
		  changelog-records)
	      (release-mail-to-html-match
	       'release-mail-to-html-body-separator-regexp
	       'point-min
	       nil
	       (assoc type release-mail-to-html-regexp-alist))
	      (while
		  (setq result
			(release-mail-to-html-match
			 'release-mail-to-html-changelog-regexp
			 nil
			 'delete
			 (assoc type release-mail-to-html-regexp-alist)))
		(setq changelog-name (plist-get result :change-log-name))
		(while
		    (setq result
			  (release-mail-to-html-match
			   'release-mail-to-html-changelog-record-regexp
			   nil
			   'delete
			   (assoc type release-mail-to-html-regexp-alist)))
		  (if (= (length (plist-get result :email-address)) 0)
		      (warn
		       "release-mail-to-html: %s contains entry %s\nnot conforming to %S."
		       buffer
		       (plist-get result :record)
		       'release-mail-to-html-changelog-record-regexp))
		  (setq changelog-records
			(concat changelog-records (plist-get result :record))))
		(setq release-mail-to-html-changelog-alist
		      (append
		       release-mail-to-html-changelog-alist
		       (list
			(cons
			 changelog-name
			 changelog-records))))
		(setq changelog-name nil changelog-records nil)))
	    ;; Extract applied patches from announcement body.
	    (release-mail-to-html-match
	     'release-mail-to-html-body-separator-regexp
	     'point-min
	     nil
	     (assoc type release-mail-to-html-regexp-alist))
	    (while
		(setq result
		      (release-mail-to-html-match
		       'release-mail-to-html-patch-regexp
		       nil
		       'delete
		       (assoc type release-mail-to-html-regexp-alist)))
	      (let ((patch-entry-min (match-beginning 0))
		    (patch-entry-max (match-end 0)))
		(setq release-mail-to-html-patch-list
		      (append
		       release-mail-to-html-patch-list
		       (list
			(list
			 (plist-get result :from)
			 (plist-get result :subject)
;		       (sjt/message-id-to-url
			 (plist-get result :reference)
;			)
			 ))))))
	    ;; Get remaining free-form announcement body.
	    (goto-char (point-min))
	    (save-excursion
	      (replace-regexp "\n+\\'" "")) ; remove empty trailing lines.
	    ;; Search forward to end of headers, as defined by
	    ;; `release-mail-to-html-body-separator-regexp'.
	    ;; Delete (match-string 1), which is the mail composition
	    ;; body/head separator.  This allows the XRE to update the
	    ;; website before sending the release announcement (time
	    ;; travel!).
	    (setq result
		  (release-mail-to-html-match
		   'release-mail-to-html-body-separator-regexp
		   nil
		   'delete
		   (assoc type release-mail-to-html-regexp-alist)))
	    ;; Process mail header, if any.
	    (if (> (point) (point-min))
		(save-restriction
		  (narrow-to-region
		   (point-min)
		   (- (point) 1))
		  (goto-char (point-min))
		  (delete-non-matching-lines
		   (car
		    (plist-get (cdr
				(assoc type
				       release-mail-to-html-regexp-alist))
			       'release-mail-to-html-headers-to-keep-regexp))))
	      (error "release-mail-to-html: %s misses mail headers." buffer))
	    (goto-char (point-min))
	    (setq release-mail-announcement
		  (buffer-substring
		   (point-min)
		   (point-max)))
	    ;; Generate list of index items
	    ;; APA: Make sure to keep this order the reverse of the actual
	    ;; document sections (because I cons here, adding to the head
	    ;; of the list).
	    (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-to-html-summary-alist
	      (setq
	       release-mail-index
	       (cons "summary" release-mail-index)))
	    (when release-mail-announcement
	      (setq
	       release-mail-index
	       (cons "announcement" release-mail-index)))
	    (setq
	     content-buffer
	     (generate-new-buffer-name
	      (format "%s.content"
		      (or
		       xemacs-version-from-subject
		       code-name-from-subject))))
	    ;; Generate XML/XHTML/HTML document.
	    (with-output-to-temp-buffer
		content-buffer
	      (princ
	       (format "%%title%%
%s
%%author%%
automatically generated from release announcement by release-mail-to-html.el
%%main%%
"
		       subject))
	      (when release-mail-announcement
		(princ
		 (format
		  "          <h1><a name=\"announcement\">%s</a></h1>\n"
		  subject))
		(princ
		 (release-mail-index release-mail-index "announcement"))
		(princ
		 (format
		  "            <pre xml:space=\"preserve\">\n%s</pre>\n"
		  release-mail-announcement)))
	      (when
		  (and
		   (or
		    xemacs-version-from-subject
		    code-name-from-subject)
		   release-mail-to-html-summary-alist)
		(princ
		 (format
		  "            <h1><a name=\"summary\">Changes</a> in %s%s%s</h1>\n"
		  type
		  (concat " " xemacs-version-from-subject)
		  (concat " "  code-name-from-subject)))
		(princ
		 (release-mail-index release-mail-index "summary"))
		(mapc
		 ;; Handle a single summary of release-mail-to-html-summary-alist:
		 (function
		  (lambda (s)
		    (if (not (cdr s))
			;; Print summary entry as paragraph, because it
			;; has no summary items.
			(princ (format "            <p>%s</p>\n" (car s)))
		      ;; Print summary name:
		      (princ (format "            <h2>%s</h2>\n" (car s)))
		      ;; Print summary items as unordered list:
		      (princ (format "            <ul>\n"))
		      ;; Handle list of summary items:
		      (mapc
		       ;; Handle single summary item:
		       (function
			(lambda (sil)
			  (princ (format "              <li>%s</li>\n" sil))))
		       (cdr s))
		      (princ (format "            </ul>\n")))))
		 release-mail-to-html-summary-alist))
	      (when (and
		     (or
		      xemacs-version-from-subject
		      code-name-from-subject)
		     release-mail-to-html-changelog-alist)
		(princ
		 (format
		  "            <h1><a name=\"changes\">ChangeLogs</a> for %s%s%s</h1>\n"
		  type
		  (concat " " xemacs-version-from-subject)
		  (concat " "  code-name-from-subject)))
		(princ
		 (release-mail-index release-mail-index "changes"))
		(princ
		 (format
		  "            <ul>\n"))
		(mapc
		 (function
		  (lambda (l)
		    (princ
		     (format
		      "              <li>ChangeLog Entries from <a href=\"#%s\">%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
		      "            <h2>ChangeLog Entries from <a name=\"%s\">%s</a></h2>\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\">Patches</a> in %s%s%s</h1>\n"
			 type
			 (concat " " xemacs-version-from-subject)
			 (concat " "  code-name-from-subject)))
		(princ
		 (release-mail-index release-mail-index "patches"))
		(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
		content-buffer
	      (goto-char (point-min))
	      (while
		  (setq result
			(release-mail-to-html-match
			 'release-mail-to-html-preformatted-regexp
			 nil
			 nil
			 (assoc type release-mail-to-html-regexp-alist)))
		(html-quote-region
		 (match-beginning 1)
		 (match-end 1))))
	    ;; Add Local variables for PSGML at end of content file.
	    (with-current-buffer
		content-buffer
	      (goto-char (point-max))
	      (insert
	       (format
		"\n<!-- Keep this comment at the end of the file\n%s %s
mode: xml
sgml-omittag:nil
sgml-shorttag:nil
sgml-namecase-general:nil
sgml-general-insert-case:lower
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:2
sgml-indent-data:t
sgml-parent-document:(\"../template.html\" \"html\" \"body\" \"table\" \"tr\" \"td\")
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->\n"
		;; Disguise the local variable bit so that we don't enter
		;; xml-mode in the emacs-lisp source file.
		"Local"
		"variables:")))
	    content-buffer))))))

(defun release-mail-to-html-match (kind goto delete args)
  (let* ((case-fold-search t)
	 (plist
	  (plist-get (cdr args) kind))
	 (regexp (car plist))
	 (sub-matches-alist (plist-to-alist (cdr plist)))
	 matches)
    (cond
     ((functionp goto)
      (goto-char (funcall goto)))
     ((stringp goto)
      (goto-char (point-min))
      (re-search-forward
       goto
       nil t))
     ((null goto))
     (t
      (error
       "release-mail-to-html-match: invalid goto argument (%S)" goto)))
    (and
     (re-search-forward
      regexp
      nil t)
     sub-matches-alist
     (setq matches
	   (append
	    (mapcar
	     (function (lambda (matches)
			 (cons (car matches) (match-string (cdr matches)))))
	     sub-matches-alist)
	    matches)))
    (when
	(and matches delete)
      (delete-region
       (match-beginning 0)
       (match-end 0)))
    (alist-to-plist matches)))

(defun release-mail-markup-author (author)
  "internal function"
  (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)
  "internal function"
  (if
      (string-match
       "\\`\\(http\\|ftp\\)://" url)
      (format
       "<a href=\"%s\">%s</a>"
       url url)
    url))

(defun release-mail-markup-subject (subject)
  "internal function"
  (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 &optional we-are-here)
  "internal function"
  (if items
      (concat
       "            <p>goto "
       (mapconcat
        (function
         (lambda (i)
           (if (and
                we-are-here
                (string= i we-are-here))
               (format "%s" i)
             (format "<a href=\"#%s\">%s</a>" i i))))
        items
        ",\n              ")
       "</p>\n")
    ""))

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