Quellcode durchsuchen

WIP, tracking down some bugs with IRC help

Lily Carpenter vor 9 Jahren
Ursprung
Commit
9b71ba24c4
1 geänderte Dateien mit 26 neuen und 14 gelöschten Zeilen
  1. 26 14
      mailfilter-parse.lisp

+ 26 - 14
mailfilter-parse.lisp

@@ -106,7 +106,7 @@
106 106
 
107 107
 (defun parse-if-line (line hash)
108 108
   (if (test-for-if line)
109
-      (let* ((regex (get-regex line))
109
+      (let* ((regex (cl-ppcre:create-scanner (get-regex line)))
110 110
              (regex-hash (make-regex-hash regex)))
111 111
         (setf (gethash "patterns" hash) (append (gethash "patterns" hash) (list regex-hash)))
112 112
         regex-hash)))
@@ -126,24 +126,36 @@
126 126
       (loop-file-until s (lambda (x) (declare (ignore x)))  #'parse-line hash))
127 127
     hash))
128 128
 
129
-(defun message-match (message-string pattern)
130
-  (let ((scanner (cl-ppcre:create-scanner (gethash "regex" pattern) :multi-line-mode t)))
131
-    (funcall scanner message-string)))
129
+(defun message-match (message pattern)
130
+  (let* ((scanner (gethash "regex" pattern))
131
+         (sb-impl::*default-external-format* :latin-1)
132
+         (message-stream (mel:message-header-stream message))
133
+         (test))
134
+    (loop for line = (read-line message-stream nil 'eof) do
135
+      (with-open-file (*standard-output*
136
+                       "/tmp/debug_data"
137
+                       :direction :output
138
+                       :if-exists :supersede)
139
+        (princ line))
140
+      (or (eq line 'eof) (setf test (funcall scanner line)))
141
+          until (or (eq line 'eof) test))
142
+    (close message-stream)
143
+    pattern))
132 144
 
133 145
 (defun handle-command (command args message)
134 146
   (when (string= command "to")
135
-    (let ((new-folder (mel:make-maildir-folder (pathname (car args)))))
136
-      (mel:move-message message new-folder))))
147
+    (let* ((pathname (pathname (concatenate 'string (remove #\" (car args)) "/")))
148
+           (new-folder (mel:make-maildir-folder pathname))
149
+           (sb-impl::*default-external-format* :latin-1))
150
+      (mel:copy-message message new-folder))))
137 151
 
138 152
 (defun handle-message (message patterns)
139
-  (let* ((sb-impl::*default-external-format* :latin-1)
140
-         (message-string (mel:message-string message)))
141
-    (labels ((my-message-match (pattern) (message-match message-string pattern)))
142
-      (let ((result (find-if #'my-message-match patterns)))
143
-        (when result
144
-          (let ((command (gethash "command" result))
145
-                (args (gethash "args" result)))
146
-            (handle-command command args message)))))))
153
+  (labels ((my-message-match (pattern) (message-match message pattern)))
154
+    (let ((result (find-if #'my-message-match patterns)))
155
+      (when result
156
+        (let ((command (gethash "command" result))
157
+              (args (gethash "args" result)))
158
+          (handle-command command args message))))))
147 159
 
148 160
 (defun filter-maildir-folder (mailfilter &optional src-folder)
149 161
   (let* ((mailfilter-rules (read-mailfilter-file mailfilter))