Commit 433a32bb authored by David Byers's avatar David Byers
Browse files

I think I fixed bug 1636 (but have no Emacs to test on)

Detailed changes:
> 2007-06-12    <David Byers@GULAG>
>
> 	* mime.el (lyskom-mime-encode-string): Added mime-charset
> 	parameter.
>
> 	* edit-text.el (lyskom-edit-parse-headers): Changed the return
> 	value to a data type (i was going to extend it, but ended up not
> 	doing so, but the new version is easier to follow anyway).
> 	(lyskom-edit-send): Use a temporary buffer (necessary since
> 	transformation functions may alter the text) and
> 	lyskom-mime-charset-for-text to determing text encoding.
>
> 	* mime.el (lyskom-mime-charset-for-text): New function
> 	(lyskom-mime-charset-for-string): Removed.
> 	(lyskom-charset-alist): Removed. From now on, we shall rely on
> 	mm-util in XEmacs.
>
parent d8d96007
2007-06-12 <David Byers@GULAG>
* mime.el (lyskom-mime-encode-string): Added mime-charset
parameter.
* edit-text.el (lyskom-edit-parse-headers): Changed the return
value to a data type (i was going to extend it, but ended up not
doing so, but the new version is easier to follow anyway).
(lyskom-edit-send): Use a temporary buffer (necessary since
transformation functions may alter the text) and
lyskom-mime-charset-for-text to determing text encoding.
* mime.el (lyskom-mime-charset-for-text): New function
(lyskom-mime-charset-for-string): Removed.
(lyskom-charset-alist): Removed. From now on, we shall rely on
mm-util in XEmacs.
2007-06-10 <David Byers@GULAG>
Better display of texts claiming to be us-ascii:
......
......@@ -105,6 +105,12 @@ See lyskom-edit-handler.")
(defvar lyskom-edit-return-to-configuration nil
"Status variable for an edit-buffer.")
(def-komtype lyskom-text-headers
((subject :read-only t)
(misc-info :read-only t)
(aux-items :read-only t)))
;;; Error signaled by lyskom-edit-parse-headers
(put 'lyskom-edit-text-abort 'error-conditions
'(error lyskom-error lyskom-edit-error lyskom-edit-text-abort))
......@@ -472,6 +478,8 @@ This runs `kom-send-text-hook' and (for backwards compatibility)
(headers nil)
(misc-list nil)
(subject nil)
(subject-start-pos nil)
(body-start-pos nil)
(message nil)
(aux-list nil))
......@@ -487,9 +495,9 @@ This runs `kom-send-text-hook' and (for backwards compatibility)
(save-excursion
(setq headers (lyskom-edit-parse-headers)
misc-list (apply 'lyskom-create-misc-list
(elt headers 1))
aux-list (elt headers 2)
subject (car headers)))
(lyskom-text-headers->misc-info headers))
aux-list (lyskom-text-headers->aux-items headers)
subject (lyskom-text-headers->subject headers)))
;;
;; Check that there is a subject
......@@ -558,13 +566,15 @@ This runs `kom-send-text-hook' and (for backwards compatibility)
(lyskom-mime-decode-content-type
(aux-item->data (car content-type)))
'charset)))
(mime-charset (lyskom-mime-string-charset full-message)))
(mime-charset (with-temp-buffer
(insert full-message)
(lyskom-mime-charset-for-text (point-min) (point-max)))))
;; If the charset isn't already set, encode the string
(if (and mime-charset (null charset))
(setq full-message
(lyskom-mime-encode-string full-message))
(lyskom-mime-encode-string full-message mime-charset))
(when (lyskom-j-or-n-p 'too-many-languages)
(keyboard-quit)))
......@@ -1173,7 +1183,7 @@ WINDOW plus any optional arguments given in ARG-LIST."
(let* ((buffer (current-buffer))
(window (selected-window))
(headers (condition-case nil
(elt (lyskom-edit-parse-headers) 1)
(lyskom-text-headers->misc-info (lyskom-edit-parse-headers))
(lyskom-edit-error nil))) ; Ignore these errors
(no nil))
(while headers
......@@ -1298,12 +1308,12 @@ text was."
(defun lyskom-edit-move-recipients (conf-stat insert-at edit-buffer)
(save-excursion
(set-buffer edit-buffer)
(let* ((tmp (lyskom-edit-parse-headers))
(subject (car tmp))
(let* ((headers (lyskom-edit-parse-headers))
(subject (lyskom-text-headers->subject headers))
(miscs (mapcar (lambda (x) (if (eq (car x) 'RECPT)
(cons 'CC-RECPT (cdr x)) x))
(cdr (lyskom-edit-translate-headers (elt tmp 1)))))
(aux-list (elt tmp 2))
(cdr (lyskom-edit-translate-headers (lyskom-text-headers->misc-info headers)))))
(aux-list (lyskom-text-headers->aux-items headers))
(elem nil))
......@@ -1329,16 +1339,16 @@ text was."
(save-excursion
(set-buffer edit-buffer)
(let* ((headers (lyskom-edit-parse-headers))
(miscs (lyskom-edit-translate-headers (elt headers 1)))
(miscs (lyskom-edit-translate-headers (lyskom-text-headers->misc-info headers)))
(elem (lyskom-edit-find-misc miscs lyskom-recpt-types-list
recpt-no)))
(cond (elem (setcar elem recpt-type))
(t (setq miscs
(append miscs (list (cons recpt-type recpt-no))))))
(lyskom-edit-replace-headers (elt headers 0)
(lyskom-edit-replace-headers (lyskom-text-headers->subject headers)
miscs
(elt headers 2)))))
(lyskom-text-headers->aux-items headers)))))
(defun lyskom-edit-add-recipient/copy (prompt &optional what-to-do recpt-type)
......@@ -1400,15 +1410,15 @@ RECPT-TYPE is the type of recipient to add."
(save-excursion
(set-buffer edit-buffer)
(let* ((headers (lyskom-edit-parse-headers))
(miscs (lyskom-edit-translate-headers (elt headers 1)))
(miscs (lyskom-edit-translate-headers (lyskom-text-headers->misc-info headers)))
(elem (lyskom-edit-find-misc miscs lyskom-recpt-types-list
recpt-no)))
(when elem (setcar elem nil))
(lyskom-edit-replace-headers (elt headers 0)
(lyskom-edit-replace-headers (lyskom-text-headers->subject headers)
miscs
(elt headers 2)))))
(lyskom-text-headers->aux-items headers)))))
(defun kom-edit-add-cross-reference ()
......@@ -1677,10 +1687,8 @@ non-nil. If MATCH-NUMBER is 'angled, only match a number inside <>."
(defun lyskom-edit-parse-headers ()
"Parse the headers of an article.
They are returned as a list where the first element is the subject,
and the rest is a list (HEADER DATA HEADER DATA ...), where HEADER is
either 'RECPT, 'CC-RECPT, 'COMM-TO or 'FOOTN-TO. This is to make it
easy to use the result in a call to `lyskom-create-misc-list'."
The value returned is a lyskom-text-headers structure."
(goto-char (point-min))
(let ((misc nil)
(subject nil)
......@@ -1727,7 +1735,7 @@ easy to use the result in a call to `lyskom-create-misc-list'."
(t (signal 'lyskom-unknown-header (list 'unknown-header (point))))))
(forward-line 1)))
(list subject misc aux)))
(lyskom-create-lyskom-text-headers subject misc aux)))
(defun lyskom-edit-parse-aux-item ()
(let ((definitions lyskom-aux-item-definitions)
......
......@@ -33,62 +33,38 @@
(concat lyskom-clientversion-long
"$Id$\n"))
(defvar lyskom-charset-alist
`(((ascii) . iso-8859-1)
((ascii latin-iso8859-1) . iso-8859-1)
,@(condition-case nil
(when (lyskom-coding-system-get 'mule-utf-8 'safe-charsets)
(list (cons (lyskom-coding-system-get 'mule-utf-8
'safe-charsets)
'utf-8)))
(error nil))
((ascii latin-iso8859-2) . iso-8859-2)
((ascii latin-iso8859-3) . iso-8859-3)
((ascii latin-iso8859-4) . iso-8859-4)
((ascii cyrillic-iso8859-5) . iso-8859-5)
((ascii arabic-iso8859-6) . iso-8859-6)
((ascii greek-iso8859-7) . iso-8859-7)
((ascii hebrew-iso8859-8) . iso-8859-8)
((ascii latin-iso8859-9) . iso-8859-9)
((ascii latin-iso8859-15) . iso-8859-15)
((ascii latin-jisx0201
japanese-jisx0208-1978 japanese-jisx0208) . iso-2022-jp)
((ascii latin-jisx0201
katakana-jisx0201 japanese-jisx0208) . shift_jis)
((ascii korean-ksc5601) . euc-kr)
((ascii chinese-gb2312) . gb2312)
((ascii chinese-big5-1 chinese-big5-2) . big5)
((ascii latin-iso8859-1 greek-iso8859-7
latin-jisx0201 japanese-jisx0208-1978
chinese-gb2312 japanese-jisx0208
korean-ksc5601 japanese-jisx0212) . iso-2022-jp-2)
))
(defun lyskom-mime-string-charset (data)
(let* ((cs (lyskom-find-charset-string data))
(the-cs (and (eq (length cs) 1) (car cs)))
(tmp lyskom-charset-alist)
(best-guess (let ((system nil))
(while (and tmp cs)
(if (or (lyskom-subset-p cs (car (car tmp)))
(eq the-cs (cdr (car tmp))))
(setq system (cdr (car tmp)) tmp nil)
(setq tmp (cdr tmp))))
system)))
(or
best-guess
(lyskom-xemacs-or-gnu
lyskom-server-coding-system
(let ((coding (lyskom-find-coding-systems-for-charsets cs)))
(while (and (car coding)
(null (or (lyskom-coding-system-get (car coding) 'mime-charset)
(lyskom-coding-system-get (car coding) :mime-charset))))
(setq coding (cdr coding)))
(and (car coding)
(or (lyskom-coding-system-get (car coding) 'mime-charset)
(lyskom-coding-system-get (car coding) :mime-charset)))))
lyskom-server-coding-system)))
(lyskom-external-function mm-find-mime-charset)
(defun lyskom-mime-charset-for-text-xemacs (start end)
(when (and (lyskom-try-require 'un-define)
(lyskom-try-require 'mm-util))
(mm-find-mime-charset start end)))
(defun lyskom-mime-charset-for-text-gnu (start end)
(let ((codings (delq nil
(mapcar (lambda (cs)
(cond ((eq cs 'undecided) lyskom-server-coding-system)
((eq cs 'compound-text) nil)
((or (coding-system-get cs 'mime-charset)
(coding-system-get cs ':mime-charset)))))
(find-coding-systems-region start end)))))
(cond ((memq lyskom-server-coding-system codings) lyskom-server-coding-system)
((lyskom-traverse cs kom-preferred-charsets
(when (memq cs codings)
(lyskom-traverse-break cs))))
(t (car codings)))))
(defun lyskom-mime-charset-for-text (start end)
"Determine which MIME charset to use for region START..END.
If the server coding system is valid for the text, it will be
returned. Otherwise charsets are returned based on Emcas idea
of coding system priority.
In XEmacs, this function will only work if mm-util from Gnus
is present and follows the expected conventions."
(lyskom-xemacs-or-gnu
(lyskom-mime-charset-for-text-xemacs start end)
(lyskom-mime-charset-for-text-gnu start end)))
(defun lyskom-mime-charset-coding-system (charset)
(condition-case nil
......@@ -96,9 +72,8 @@
charset)
(error 'raw-text)))
(defun lyskom-mime-encode-string (data)
(let* ((mime-charset (lyskom-mime-string-charset data))
(coding-system (lyskom-mime-charset-coding-system mime-charset)))
(defun lyskom-mime-encode-string (data mime-charset)
(let* ((coding-system (lyskom-mime-charset-coding-system mime-charset)))
(when (and mime-charset coding-system)
(cons mime-charset (lyskom-encode-coding-string data coding-system)))))
......
......@@ -3432,6 +3432,21 @@ numeric reference.
Values other than `t' and `nil' are reserved for future use."
server)
(def-kom-var kom-preferred-charsets '(iso-8859-1 utf-8)
"**Character sets to try encoding texts with.
Thie setting may contain a list of valid MIME character sets. When
encoding a text to send to the server, the client will use the default
server character set whenever possible. If it is insufficient, it will
try the character sets listed in this setting, in order. If they are
also insufficient, it will attempt to find some other character set
that works.
WARNING: this setting only applies to Gnu Emacs. In XEmacs, customize
the variable mm-coding-system-priorities instead; you may have to load
Gnus in order to do so."
server)
(def-kom-var kom-mercial nil
"**What you are doing when you're done reading.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment