瀏覽代碼

Fix known bugs, yay safety 0 (thanks cl-ppcre)

Lily Carpenter 9 年之前
父節點
當前提交
cdbbfa6068
共有 1 個文件被更改,包括 11 次插入14 次删除
  1. 11 14
      mailfilter-parse.lisp

+ 11 - 14
mailfilter-parse.lisp

@@ -98,15 +98,16 @@
98 98
 (defun get-regex (line)
99 99
   (second (split-sequence:split-sequence #\/ line)))
100 100
 
101
-(defun make-regex-hash (regex)
101
+(defun make-regex-hash (regex scanner)
102 102
   (let ((regex-hash (make-hash-table :test 'equal)))
103
-    (setf (gethash "regex" regex-hash) regex)
103
+    (setf (gethash "regex" regex-hash) (list regex scanner))
104 104
     regex-hash))
105 105
 
106 106
 (defun parse-if-line (line hash)
107 107
   (if (test-for-if line)
108
-      (let* ((regex (cl-ppcre:create-scanner (get-regex line)))
109
-             (regex-hash (make-regex-hash regex)))
108
+      (let* ((regex (get-regex line))
109
+             (scanner (cl-ppcre:create-scanner regex))
110
+             (regex-hash (make-regex-hash regex scanner)))
110 111
         (setf (gethash "patterns" hash) (append (gethash "patterns" hash) (list regex-hash)))
111 112
         regex-hash)))
112 113
 
@@ -126,27 +127,23 @@
126 127
     hash))
127 128
 
128 129
 (defun message-match (message pattern)
129
-  (let* ((scanner (gethash "regex" pattern))
130
+  (let* ((scanner (cadr (gethash "regex" pattern)))
131
+         (regex (car (gethash "regex" pattern)))
130 132
          (sb-impl::*default-external-format* :latin-1)
131 133
          (test))
132 134
     (with-open-stream (message-stream (mel:message-header-stream message))
133 135
       (loop for line = (read-line message-stream nil)
134 136
             while (and line (not test))
135 137
             do
136
-               (with-open-file (*standard-output*
137
-                                "/tmp/debug_data"
138
-                                :direction :output
139
-                                :if-exists :supersede)
140
-                 (princ line))
141
-               (setf test (funcall scanner line))))
142
-    pattern))
138
+               (setf test (cl-ppcre:scan scanner line))))
139
+    test))
143 140
 
144 141
 (defun handle-command (command args message)
145 142
   (when (string= command "to")
146 143
     (let* ((pathname (pathname (concatenate 'string (remove #\" (car args)) "/")))
147
-           (new-folder (mel:make-maildir-folder pathname))
144
+           (new-folder (mel:make-maildir-folder pathname :if-does-not-exist :create))
148 145
            (sb-impl::*default-external-format* :latin-1))
149
-      (mel:copy-message message new-folder))))
146
+      (mel:move-message message new-folder))))
150 147
 
151 148
 (defun handle-message (message patterns)
152 149
   (labels ((my-message-match (pattern) (message-match message pattern)))