On Tue, 20 Jan 2009, Volkan YAZICI <[email protected]> writes:
> In various places of the BBDB source code, it uses (downcase name) like
> tricks to compare the identifiers, e.g. aka names. But default downcase
> function of emacs uses current LC_CTYPE that emacs session is
> initialized with. As a result of this, when gnus receives messages
> encoded in different locales, bbdb doesn't switch to the case conversion
> table related mail locale is set to and `downcase' doesn't work as it
> should. Consider below case.
>
> - Emacs is initialized with en_US.UTF-8 locale,
> - And mail is encoded in tr_TR.UTF-8 where "From:" line is "İI".
>
> By default, (downcase name) will return "İi", which is obviously
> broken. (The correct conversion should be "iı".)
>
> I searched previous posts[1] regarding with the similar issues, which
> recommends (funcall 'string-make-unibyte name) like hacks, but this
> doesn't solve the problem too. (Locale is still not changed during
> conversion.)
>
> (let ((name (string-make-unibyte "İI")))
> (list name (downcase name)))
> => ("\320I" "\320i")
>
> I'm not very good at BBDB internals. Could somebody help me to fix the
> problem?
I'm not very good at emacs lisp hacking, but here is my ad-hoc solution
to the problem.
;;; tr_TR.UTF-8 to ASCII Translation
(defvar tr-utf8-to-ascii-translation-alist
'((?ç . ?c) (?Ç . ?C)
(?ğ . ?g) (?Ğ . ?G)
(?ı . ?i) (?İ . ?I)
(?ö . ?o) (?Ö . ?O)
(?ş . ?s) (?Ş . ?S)
(?ü . ?u) (?Ü . ?U)))
(defun tr-utf8-to-ascii (start end)
"Converts supplied text region of tr_TR.UTF-8 locale to ASCII format."
(interactive "r")
(translate-region
start end (make-translation-table tr-utf8-to-ascii-translation-alist)))
;; Fix `bbdb-check-alternate-name' to handle Turkish characters in a smarter
;; way while downcasing.
(defun bbdb-normalize-name (name)
"Normalizes (hairy downcasing) given string parameter."
(coerce
(mapcar
(lambda (char)
(downcase
(or (cdr (assoc char tr-utf8-to-ascii-translation-alist))
char)))
(coerce name 'list))
'string))
(defun bbdb-name= (a b)
"Return t if two names are equal after normalizing them. (See
`bbdb-normalize-name' for further details.)"
(string= (bbdb-normalize-name a) (bbdb-normalize-name b)))
(defun bbdb-check-alternate-name (possible-name record)
"If there is any, finds a suitable `bbdb-record-aka' with
respect to supplied parameters."
(dolist (aka (bbdb-record-aka record))
(when (bbdb-name= possible-name aka)
(return aka))))
And here is a small demonstration for the `bbdb-normalize-name'
function: (bbdb-normalize-name "ıIüÜşŞiİçÇöÖ") => "iiuussiiccoo".
Regards.
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
[email protected]
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/