Escape file name with safe chars.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Tue, 10 Jul 2012 18:34:22 +0300
changeset 893 0e1febcbddb6
parent 892 cdf8003f3abb
child 894 d993e3e910ef
Escape file name with safe chars.
.emacs-my
--- a/.emacs-my	Tue Jul 10 17:07:12 2012 +0300
+++ b/.emacs-my	Tue Jul 10 18:34:22 2012 +0300
@@ -1270,6 +1270,14 @@
 ;; Kill message buffer after mail send. You always can use C-c C-s to preserve it.
 (setq message-kill-buffer-on-exit t)
 
+(defconst my-safe-filename-char-regex "[[:alnum:]-_!.@]"
+  "Safe file names.")
+
+(defun my-clean-filename (filename)
+  (mapconcat
+   (lambda (ch) (or (when (string-match my-safe-filename-char-regex (char-to-string ch)) (char-to-string ch)) "-"))
+   filename "") )
+
 (defun my-message-save ()
   "Store message in `gnus-article-save-directory' after
 successful sending. It is possible that mail rejected and I lost
@@ -1278,8 +1286,8 @@
     (error "Attempt to call my-message-save in non message-mode buffer"))
   (make-directory gnus-article-save-directory t)
   (let ( (buf (current-buffer))
-         (field-to (or (message-fetch-field "Newsgroups") (message-fetch-field "To")))
-         (field-subject (message-fetch-field "Subject"))
+         (field-to (my-clean-filename (or (message-fetch-field "Newsgroups") (message-fetch-field "To"))))
+         (field-subject (my-clean-filename (message-fetch-field "Subject")))
          file )
     (setq file (concat gnus-article-save-directory "/" (format-time-string "%F_%T") "_" field-to "_" field-subject))
     (with-temp-file file