Fix charset problems in nnweb, since *nntp* is a multibyte buffer.
authorShengHuo ZHU <zsh@cs.rochester.edu>
Thu, 2 Dec 1999 16:22:47 +0000 (16:22 +0000)
committerShengHuo ZHU <zsh@cs.rochester.edu>
Thu, 2 Dec 1999 16:22:47 +0000 (16:22 +0000)
Fix another problem caused by malformed page (Searching "Stefan Monnier"
in dejanews)

lisp/ChangeLog
lisp/mm-util.el
lisp/nnweb.el

index 46ed360..7bfa8c8 100644 (file)
@@ -1,3 +1,12 @@
+1999-12-02 11:14:50  Shenghuo ZHU  <zsh@cs.rochester.edu>
+
+       * mm-util.el (mm-with-unibyte-current-buffer): New macro.
+       * nnweb.el (nnweb-retrieve-headers): Use it.
+       (nnweb-request-article): Use it.
+       
+       * nnweb.el (nnweb-dejanews-create-mapping): Set a default date in
+       case matching failed.
+
 1999-12-02  John Wiegley <jwiegley@inprise.com>
 
        * mail-source.el (mail-source-keyword-map): Add backslash to
index a23a7f6..8006fec 100644 (file)
@@ -271,6 +271,24 @@ See also `with-temp-file' and `with-output-to-string'."
 (put 'mm-with-unibyte-buffer 'lisp-indent-function 0)
 (put 'mm-with-unibyte-buffer 'edebug-form-spec '(body))
 
+(defmacro mm-with-unibyte-current-buffer (&rest forms)
+  "Evaluate FORMS there like `progn' in current buffer."
+  (let ((multibyte (make-symbol "multibyte")))
+    `(if (or (string-match "XEmacs\\|Lucid" emacs-version)
+            (not (fboundp 'set-buffer-multibyte)))
+        (progn
+          ,@forms)
+       (let ((,multibyte (default-value 'enable-multibyte-characters)))
+        (unwind-protect
+            (let ((buffer-file-coding-system mm-binary-coding-system)
+                  (coding-system-for-read mm-binary-coding-system)
+                  (coding-system-for-write mm-binary-coding-system))
+              (set-buffer-multibyte nil)
+              ,@forms)
+          (set-buffer-multibyte ,multibyte))))))
+(put 'mm-with-unibyte-current-buffer 'lisp-indent-function 0)
+(put 'mm-with-unibyte-current-buffer 'edebug-form-spec '(body))
+
 (defun mm-find-charset-region (b e)
   "Return a list of charsets in the region."
   (cond
index 7c9ec3c..25c8e6f 100644 (file)
@@ -113,9 +113,10 @@ and `altavista'.")
     (set-buffer nntp-server-buffer)
     (erase-buffer)
     (let (article header)
-      (while (setq article (pop articles))
-       (when (setq header (cadr (assq article nnweb-articles)))
-         (nnheader-insert-nov header)))
+      (mm-with-unibyte-current-buffer
+       (while (setq article (pop articles))
+         (when (setq header (cadr (assq article nnweb-articles)))
+           (nnheader-insert-nov header))))
       'nov)))
 
 (deffoo nnweb-request-scan (&optional group server)
@@ -169,7 +170,8 @@ and `altavista'.")
     (let* ((header (cadr (assq article nnweb-articles)))
           (url (and header (mail-header-xref header))))
       (when (or (and url
-                    (nnweb-fetch-url url))
+                    (mm-with-unibyte-current-buffer
+                      (nnweb-fetch-url url)))
                (and (stringp article)
                     (nnweb-definition 'id t)
                     (let ((fetch (nnweb-definition 'id))
@@ -178,8 +180,9 @@ and `altavista'.")
                         (setq art (match-string 1 article)))
                       (and fetch
                            art
-                           (nnweb-fetch-url
-                            (format fetch article))))))
+                           (mm-with-unibyte-current-buffer
+                             (nnweb-fetch-url
+                              (format fetch article)))))))
        (unless nnheader-callback-function
          (funcall (nnweb-definition 'article))
          (nnweb-decode-entities))
@@ -381,12 +384,14 @@ and `altavista'.")
                    group (nth 2 text)
                    date (nth 1 text)
                    from (nth 0 text))
-             (string-match "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)" date)
-             (setq date (format "%s %s 00:00:00 %s"
-                                (car (rassq (string-to-number
-                                             (match-string 2 date))
-                                            parse-time-months))
-                                (match-string 3 date) (match-string 1 date)))
+             (if (string-match "\\([0-9]+\\)/\\([0-9]+\\)/\\([0-9]+\\)" date)
+                 (setq date (format "%s %s 00:00:00 %s"
+                                    (car (rassq (string-to-number
+                                                 (match-string 2 date))
+                                                parse-time-months))
+                                    (match-string 3 date) 
+                                    (match-string 1 date)))
+               (setq date "Jan 1 00:00:00 0000"))
              (incf i)
              (setq url (concat url "&fmt=text"))
              (unless (nnweb-get-hashtb url)