平衡点


2025/08/09

_ Wanderlustで日本語の添付ファイルを扱う defadvice を nadvice に書き換える(again)

前回, うまく動いてなかったので revert したのだけれど, うまくできたので変更.

やりたいこと

Emacs30 から defadvice が obsolete となったので, nadvice 向けに処理を書き換える.

変更前

(with-eval-after-load 'eword-decode
  (mime-set-field-decoder
   'From nil 'eword-decode-and-unfold-unstructured-field-body)
  (mime-set-field-decoder
   'CC nil 'eword-decode-and-unfold-unstructured-field-body)
  (mime-set-field-decoder
   'To nil 'eword-decode-and-unfold-unstructured-field-body))
;;; ファイル名が日本語の添付ファイルをデコードする [semi-gnus-ja: 4332]
(eval-after-load "mime"
  '(defadvice mime-entity-filename
     (after eword-decode-for-broken-MUA activate)
     "Decode eworded file name for *BROKEN* MUA."
     (when (stringp ad-return-value)
       (setq ad-return-value (eword-decode-string ad-return-value t)))))
(eval-after-load "std11"
  '(defadvice std11-wrap-as-quoted-string (before encode-string activate)
     "Encode a string."
     (require 'eword-encode)
     (ad-set-arg 0 (or (eword-encode-string (ad-get-arg 0)) "" )) ))

変更後

(leaf eword-decode
  ;; 日本語ファイル名の添付ファイルを処理するための advice で使うために
  ;; 以下の二つを autoload 扱いにしておく
  :commands (eword-decode-string
             eword-encode-string)
  :config
  (mime-set-field-decoder
   'From nil 'eword-decode-and-unfold-unstructured-field-body)
  (mime-set-field-decoder
   'CC nil 'eword-decode-and-unfold-unstructured-field-body)
  (mime-set-field-decoder
   'To nil 'eword-decode-and-unfold-unstructured-field-body)
  )
;;; ファイル名が日本語の添付ファイルをデコードする: 元ネタ [semi-gnus-ja: 4332]
;;; ...所で, semi-gnus-ja のアーカイブってどこにあるのかしらん...
(leaf mime
  :preface
;;;###autoload
  (defun my:decode-mime-filename-around (orig-fun &rest args)
    "Decode the filename returned by the original function if it's a string."
    (let ((return-value (apply orig-fun args)))
      (if (stringp return-value)
          (progn
            (eword-decode-string return-value t))
      return-value)))
  :advice
  (:around mime-entity-filename
           my:decode-mime-filename-around)
  )
(leaf std11
  :preface
;;;###autoload
  (defun my:encode-string-filter-args (args)
    "Encode the first argument in a list of ARGS."
    (let* ((original-string (car args))
           (encoded-string (or (eword-encode-string original-string) "")))
      (cons encoded-string (cdr args))))
  :advice
  (:filter-args encode-string
                my:encode-string-filter-args)
  )

というわけで.

手元の設定ファイルからは defadvice は無くなりました.


連絡先など
最近の日記
  • 2025/08/09
    • 1. Wanderlustで日本語の添付ファイルを扱う defadvice を nadvice に書き換える(again)
  • 2025/08/08
    • 1. VirtualBox上の Windows 11 で Host OS 側の Samba でファイル共有したかっただけなんだが.
  • 2025/06/17
    • 1. org-beamer での \section*{} の扱い
  • 2025/05/20
    • 1. glibc の更新
  • 2025/04/30
    • 1. dovecot の更新でハマる.
一覧
2006|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|02|03|04|08|09|10|11|12|
2013|01|02|03|04|05|06|08|09|10|11|12|
2014|01|02|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|09|10|
2016|02|03|
2017|01|02|03|05|06|07|09|11|12|
2018|03|06|07|10|11|12|
2019|01|02|03|04|05|07|10|12|
2020|01|02|03|04|05|08|09|10|11|12|
2021|01|02|03|05|06|07|08|09|11|12|
2022|01|02|03|04|05|06|08|10|11|12|
2023|02|03|04|06|08|09|11|12|
2024|01|02|03|04|05|06|10|12|
2025|02|03|04|05|06|08|
Back to Top ▲