~ubuntu-branches/ubuntu/saucy/wl/saucy

« back to all changes in this revision

Viewing changes to elmo/utf7.el

  • Committer: Package Import Robot
  • Author(s): Tatsuya Kinoshita
  • Date: 2013-05-07 21:34:52 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20130507213452-jptte6rqr7wum3pm
Tags: 2.15.9+0.20120411-1
* Imported Upstream version 2.15.9+0.20120411
  - Switch upstream to the development snapshot, because the upstream
    version 2.14.0 released on 2005-03-25 is too old and hard to maintain.
    The upstream tarball is from Debian wheezy, package wl-beta.
* debian/*: Sync with wl-beta

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
  (concat utf7-direct-encoding-chars "+\\~")
92
92
  "Character ranges which do not need escaping in the IMAP variant of UTF-7.")
93
93
 
94
 
(defconst utf7-utf-16-coding-system (and (fboundp 'find-coding-system)
95
 
                                         (find-coding-system 'utf-16-be))
 
94
 
 
95
(eval-and-compile
 
96
  (defun utf7-find-coding-system-without-bom (cs)
 
97
    (and (fboundp 'find-coding-system)
 
98
         (find-coding-system cs)
 
99
         ;; Avoid versions with BOM.
 
100
         (= 2 (length (encode-coding-string "a" cs)))
 
101
         cs)))
 
102
 
 
103
(defconst utf7-utf-16-coding-system
 
104
  (or
 
105
   ;; Emacs 22, Emacs 23
 
106
   (utf7-find-coding-system-without-bom 'utf-16be)
 
107
   ;;
 
108
   (utf7-find-coding-system-without-bom 'utf-16-be)
 
109
   ;; Mule-UCS
 
110
   (utf7-find-coding-system-without-bom 'utf-16-be-no-signature))
96
111
  "Coding system which encodes big endian UTF-16.")
97
112
 
98
113
(defsubst utf7-imap-get-pad-length (len modulus)
121
136
                 (skip-chars-forward not-direct-encoding-chars)))
122
137
            (if (and (= fc esc-char)
123
138
                     (= run-length 1))  ; Lone esc-char?
124
 
                (delete-backward-char 1) ; Now there's one too many
 
139
                (delete-char -1)        ; Now there's one too many
125
140
              (utf7-fragment-encode p (point) for-imap))
126
141
            (insert "-")))))))
127
142
 
170
185
              (save-excursion
171
186
                (utf7-fragment-decode p (point) for-imap)
172
187
                (goto-char p)
173
 
                (delete-backward-char 1)))))))))
 
188
                (delete-char -1)))))))))
174
189
 
175
190
(defun utf7-fragment-decode (start end &optional for-imap)
176
191
  "Decode base64 encoded fragment from START to END of UTF-7 text in buffer.
196
211
                                  utf7-utf-16-coding-system)
197
212
            (set-buffer-multibyte nil)
198
213
            (goto-char (point-min))
199
 
            ;; Remove BOM (Big-endian UTF-16 FE FF)
 
214
            ;; Remove BOM (Big-endian UTF-16 FE FF) for Mule-UCS
200
215
            (while (re-search-forward "\376\377" nil t)
201
 
              (delete-region (match-beginning 0)(match-end 0))))
 
216
              (delete-region (match-beginning 0) (match-end 0))))
202
217
        (lambda ()
203
218
          (goto-char (point-min))
204
 
          ;; Add BOM (Big-endian UTF-16 FE FF)
205
 
          (insert "\376\377")
206
219
          (decode-coding-region (point-min) (point-max)
207
220
                                utf7-utf-16-coding-system)))))
208
221