-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmew-nmz.el
1686 lines (1566 loc) · 57.7 KB
/
mew-nmz.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; -*- Mode: Emacs-Lisp -*-
;;
;; mew-nmz.el --- Namazu interfaces for Mew
;;
;; Author: Hideyuki SHIRAI
;; Created: Dec 24, 2004
;;
;; Put your ~/.mew.el
;; (require 'mew-nmz)
;; (setq mew-search-method 'namazu)
;;
(require 'mew)
(eval-when-compile
(condition-case nil
(require 'w3m-namazu)
(error nil)))
;; Variables
(defconst mew-nmz-version "2010-06-08")
(defgroup mew-nmz nil
"Namazu support with Mew."
:group 'mew)
(defcustom mew-nmz-index-path "~/Namazu"
"*Namazu index top directory."
:group 'mew-nmz
:type 'directory)
(defcustom mew-nmz-index-mail "Mail"
"*Namazu index mail directory name."
:group 'mew-nmz
:type 'string)
(defcustom mew-nmz-setup-hook nil
"*Hook called on mew-nmz-setup."
:group 'mew-nmz
:type 'hook)
(defcustom mew-nmz-prog "namazu"
"*Namazu program name."
:group 'mew-nmz
:type 'string)
(defcustom mew-nmz-prog-args nil
"*Namazu's arguments."
:group 'mew-nmz
:type '(repeat string))
(defcustom mew-nmz-prog-mknmz "mknmz"
"*Namazu make index program."
:group 'mew-nmz
:type 'string)
(defcustom mew-nmz-prog-mknmz-args '("--decode-base64")
"*Mknmz's argument, in addition to \"--no-encode-uri\", \"--mailnews\"."
:group 'mew-nmz
:type '(repeat string))
(defcustom mew-nmz-prog-mknmz-include "~/Namazu/mknmz-inc.pl"
"*Include file for mknmz."
:group 'mew-nmz
:type 'file)
(defcustom mew-nmz-mknmz-skip-folders-regexp
(mapcar 'regexp-quote
(delq nil
`(,mew-draft-folder ,mew-trash-folder ,mew-queue-folder ,mew-attach-folder
,mew-imap-queue-folder ,mew-imap-trash-folder ,mew-postq-folder
,@mew-trash-folder-list ,@mew-imap-trash-folder-list
"+schedule")))
"*Folders regexp to skip the index creating."
:group 'mew-nmz
:type '(repeat regexp))
(defcustom mew-nmz-mknmz-use-mode-line t
"*Display indicator of namazu in mode line."
:group 'mew-nmz
:type 'boolean)
(defcustom mew-nmz-line-id '("Mew(nmz): %7b")
"*A value of mode-line-buffer-identification for Mew summary mode, when mknmzing."
:group 'mew-nmz
:type '(list string))
(defcustom mew-nmz-mknmz-timer-interval 0.1
"*Seconds of interval to execute next mknmz."
:group 'mew-nmz
:type 'number)
(defcustom mew-nmz-pick-default-field nil
"*Default prefix string to be appeared when inputting a namazu pick pattern.
A good example is \"+from:\"."
:group 'mew-nmz
:type '(choice string (const nil)))
(defcustom mew-nmz-pick-field-list
'("subject=" "from=" "to=" "newsgroups=" "date="
"message-id=" "cc=" "in-reply-to=" "references=")
"*A list of key for namazu pick pattern."
:group 'mew-nmz
:type '(repeat string))
(defcustom mew-nmz-pick-gather-field-list
`((,mew-from: address "from=" "to=" "cc=")
(,mew-to: address "from=" "to=" "cc=")
(,mew-cc: address "from=" "to=" "cc=")
(,mew-message-id: msgid "message-id=" "in-reply-to=" "references=")
(,mew-in-reply-to: msgid "message-id=" "in-reply-to=" "references=")
(,mew-references: msgid "message-id=" "in-reply-to=" "references="))
"*A list of completion keyword from message."
:group 'mew-nmz
:type '(repeat (list string
(choice (const address) (const msgid))
string string string)))
(defcustom mew-nmz-search-parent-folder `(,mew-inbox-folder)
"*Search folder for parent or child, "
:group 'mew-nmz
:type '(repeat string))
(defcustom mew-nmz-db-max 64
"*Namazu max index.
This value MUST be less then equal `INDEX_MAX' of libnamazu.h."
:group 'mew-nmz
:type 'integer)
(defcustom mew-nmz-query-max-length 256
"*Namazu query string max length.
This value MUST be less then equal `QUERY_MAX' of libnamazu.h."
:group 'mew-nmz
:type 'integer)
(defcustom mew-nmz-mark-pick mew-mark-review
"*Mark for Namazu pick."
:group 'mew-nmz
:type 'character)
(defcustom mew-nmz-mark-unindexed mew-mark-review
"*Mark for type unindexed messages."
:group 'mew-nmz
:type 'character)
(defcustom mew-ask-virtual-folder-name nil
"*If *non-nil*, ask a virtual folder name."
:group 'mew-summary
:type 'boolean)
(defcustom mew-nmz-cache-file-prefix ".mew-nmz-"
"*Prefix of the cache filename. Expand with mew-conf-path when use it."
:group 'mew-nmz
:type 'string)
(defcustom mew-nmz-mknmz-index-file ".mewmknmz"
"*File name of the input file of mewmknmz. Expand with mew-conf-path when use it."
:group 'mew-nmz
:type 'string)
(defcustom mew-nmz-input-folders-asterisk t
"*Add \"*\" at the end of input folder name."
:group 'mew-nmz
:type 'boolean)
(defcustom mew-nmz-prog-gcnmz "gcnmz"
"*Program name for the garbage collection."
:group 'mew-nmz
:type 'string)
(defcustom mew-nmz-use-gcnmz-folders-regexp `(,(regexp-quote mew-inbox-folder))
"*Folders regexp to execute gcnmz."
:group 'mew-nmz
:type '(repeat regexp))
(defcustom mew-nmz-gcnmz-line-id '("Mew(gcn): %7b")
"*A value of mode-line-buffer-identification for Mew summary mode, when gcnmzing."
:group 'mew-nmz
:type '(list string))
(defcustom mew-nmz-prog-rfnmz "rfnmz"
"*Program name for the re-index."
:group 'mew-nmz
:type 'string)
(defcustom mew-nmz-mknmz-index-file-coding-system
(when (boundp 'default-file-name-coding-system)
default-file-name-coding-system)
"*Coding system of index-file."
:group 'mew-nmz
:type '(coding-system :size 0))
;; internal variable, don't modify.
(defvar mew-nmz-gather-header-list nil)
(defvar mew-nmz-indexed-folders nil)
(defvar mew-nmz-input-folder-hist nil)
(defvar mew-nmz-mknmz-process nil)
(defvar mew-nmz-mknmz-process-folder nil)
(defvar mew-nmz-mknmz-process-file nil)
(make-variable-buffer-local 'mew-nmz-mknmz-process)
(make-variable-buffer-local 'mew-nmz-mknmz-process-folder)
(make-variable-buffer-local 'mew-nmz-mknmz-process-file)
(defconst mew-nmz-namazu-index-alias "_mew-namazu"
"*Alias name for mew-nmz-namazu.")
(defvar mew-nmz-namazu-content-type "message/mew")
(defvar mew-nmz-namazu-pattern nil)
(defvar mew-nmz-namazu-miss-folders nil)
(defvar mew-nmz-setup-p nil)
(defvar mew-nmz-imap-case-alist nil)
(defvar mew-nmz-nntp-case-alist nil)
(defvar mew-nmz-pop-case-alist nil)
(defvar mew-nmz-fld-index-alist nil)
(defvar mew-nmz-url-fld-alist nil)
(defvar mew-nmz-mknmz-all-folders nil)
(defvar mew-nmz-mknmz-continue-timer nil)
(defvar mew-nmz-mknmz-lang-alist
'(("Japanese" "ja")))
(defvar mew-nmz-cs-index (cond
((mew-coding-system-p 'euc-japan-unix)
'euc-japan-unix)
((mew-coding-system-p 'euc-jp-unix)
'euc-jp-unix)
(t mew-cs-text-for-write))
"*Coding system to write 'NMZ.field.uri'.")
(defconst mew-nmz-result-regex
(concat "^\\(.*\\)" (regexp-quote mew-path-separator) "\\([0-9]+\\)"))
(defconst mew-nmz-use-drive-letter
(memq system-type '(OS/2 emx windows-nt cygwin)))
;; Set up
(defvar mew-nmz-search-method `(namazu "Namazu" ,mew-nmz-prog
mew-nmz-search
mew-nmz-search-virtual
mew-nmz-mknmz
mew-nmz-mknmz-all-folders
mew-nmz-pick-canonicalize-pattern))
(eval-after-load "mew-search"
`(setq mew-search-switch
(cons mew-nmz-search-method mew-search-switch)))
;; (define-key mew-summary-mode-map "k" (make-sparse-keymap))
;; (define-key mew-summary-mode-map "kc" 'mew-summary-search-change-method)
;; (define-key mew-summary-mode-map "k?" 'mew-summary-search)
;; (define-key mew-summary-mode-map "k/" 'mew-summary-selection-by-search)
;; (define-key mew-summary-mode-map "km" 'mew-summary-make-index-folder)
;; (define-key mew-summary-mode-map "kM" 'mew-summary-make-index-all)
(add-hook 'mew-summary-mode-hook
(lambda ()
(define-key mew-summary-mode-map "kg" 'mew-nmz-gcnmz)
(define-key mew-summary-mode-map "ks" 'mew-nmz-mknmz-save-mewmknmz)
(define-key mew-summary-mode-map "kK" 'mew-nmz-mknmz-kill-process)
(define-key mew-summary-mode-map "ku" 'mew-nmz-mark-unindexed)
(define-key mew-summary-mode-map "k^" 'mew-nmz-search-parent)
(define-key mew-summary-mode-map "kp" 'mew-nmz-search-parent)
(define-key mew-summary-mode-map "kn" 'mew-nmz-search-child)
(define-key mew-summary-mode-map "kN" 'mew-nmz-namazu)
(define-key mew-summary-mode-map "kj" 'mew-nmz-jump-message)))
(add-hook 'mew-message-mode-hook
(lambda ()
(define-key mew-message-mode-map "k" (make-sparse-keymap))
(define-key mew-message-mode-map "kp" 'mew-nmz-search-msgid-at-point)
(define-key mew-message-mode-map "kr" 'mew-nmz-search-msgid-region)))
(defun mew-nmz-pick-field-list ()
(let ((lst (append mew-pick-field-list
mew-nmz-pick-field-list
(mew-nmz-pick-pattern-gather-header))))
(mew-uniq-list lst)))
(defadvice mew-summary-search (around mew-nmz activate compile)
"Use mew-nmz gather-header."
(if (eq mew-search-method 'namazu)
(let ((mew-pick-field-list (mew-nmz-pick-field-list)))
ad-do-it)
ad-do-it))
(defadvice mew-summary-selection-by-search (around mew-nmz activate compile)
"Use mew-nmz gather-header."
(if (eq mew-search-method 'namazu)
(let ((mew-pick-field-list (mew-nmz-pick-field-list)))
ad-do-it)
ad-do-it))
(add-hook 'mew-summary-rename-folder-hook 'mew-nmz-folder-index-rename)
(add-hook 'mew-summary-delete-folder-hook 'mew-nmz-folder-index-delete)
(add-hook 'mew-status-update-hook 'mew-nmz-status-update)
(add-hook 'mew-quit-hook 'mew-nmz-cleanup)
(when (and (featurep 'mw32script)
(fboundp 'define-process-argument-editing))
;; Argument setting for mknmz.bat, gcnmz.bat, rfnmz.bat
(let ((progs '("mknmz" "gcnmz" "rfnmz"))
prog)
(while progs
(setq prog (mew-which-exec (car progs)))
(setq progs (cdr progs))
(when (and prog (string-match "\\.bat$" prog))
(setq prog (regexp-quote prog))
;; (general-process-argument-editing-function
;; ARGUMENT QUOTING ARGV0ISP &optional EP H2SP QP S2ISP)
(define-process-argument-editing
prog
(lambda (x) (general-process-argument-editing-function x nil nil))
'first)))))
;; macro
(defmacro mew-nmz-imap-directory-file-name (fld case)
`(condition-case nil
(mew-imap-directory-file-name ,fld ,case)
(error ,fld)))
(defmacro mew-nmz-cache-file-name (part)
`(expand-file-name (concat mew-nmz-cache-file-prefix
(symbol-name ,part)
"-alist")
mew-conf-path))
(defmacro mew-nmz-cache-alist-name (part)
`(intern (concat "mew-nmz-" (symbol-name ,part) "-alist")))
(defsubst mew-nmz-expand-folder (case:folder)
"Convert case:folder to the directory name of namazu's index."
(let* ((fld (mew-case:folder-folder case:folder))
(imapp (mew-folder-imapp fld))
(mew-mail-path (concat (file-name-as-directory mew-nmz-index-path)
mew-nmz-index-mail))
(nmzdir (directory-file-name (mew-expand-folder case:folder))))
(if (not imapp)
nmzdir
(while (string-match "[][]" nmzdir)
(setq nmzdir (concat (substring nmzdir 0 (match-beginning 0))
"%%"
(substring nmzdir (match-end 0)))))
nmzdir)))
(defsubst mew-nmz-case-folder-normalize (case:folder)
(let ((case (mew-case:folder-case case:folder))
(fld (mew-case:folder-folder case:folder))
(newcase ""))
(setq fld (directory-file-name fld))
(when (mew-folder-imapp fld)
(setq fld (mew-nmz-imap-directory-file-name fld case)))
(cond
((or (string= fld "")
(string= fld "*")
(mew-folder-imapp fld))
(setq newcase (or (cdr (assoc case mew-nmz-imap-case-alist)) "")))
((mew-folder-popp fld)
(setq newcase (or (cdr (assoc case mew-nmz-pop-case-alist)) "")))
((mew-folder-nntpp fld)
(setq newcase (or (cdr (assoc case mew-nmz-nntp-case-alist)) ""))))
(if (string= newcase "")
fld
(concat newcase ":" fld))))
(defsubst mew-nmz-case-normalize (case:folder)
(let ((case (mew-case:folder-case case:folder))
(fld (mew-case:folder-folder case:folder))
(newcase ""))
(cond
((or (string= fld "")
(string= fld "*")
(mew-folder-imapp fld))
(setq newcase (or (cdr (assoc case mew-nmz-imap-case-alist)) "")))
((mew-folder-popp fld)
(setq newcase (or (cdr (assoc case mew-nmz-pop-case-alist)) "")))
((mew-folder-nntpp fld)
(setq newcase (or (cdr (assoc case mew-nmz-nntp-case-alist)) ""))))
newcase))
(defsubst mew-nmz-folder-to-nmzdir (folder)
(mew-nmz-setup)
(cdr (assoc (directory-file-name folder) mew-nmz-fld-index-alist)))
(defsubst mew-nmz-url-to-folder (url)
(mew-nmz-setup)
(when (and mew-nmz-use-drive-letter
(string-match "^/\\([a-zA-Z]\\)|\\(/.*\\)" url))
(setq url (concat
(substring url (match-beginning 1) (match-end 1))
":"
(substring url (match-beginning 2) (match-end 2)))))
(cdr (assoc (expand-file-name url) mew-nmz-url-fld-alist)))
(defsubst mew-nmz-indexed-folder-p (fld)
(let ((nmzdir (mew-nmz-expand-folder fld)))
(and nmzdir
(file-directory-p nmzdir)
(file-exists-p (expand-file-name "NMZ.i" nmzdir)))))
;; Mew interface
(defun mew-nmz-search (pattern folder &rest args)
(mew-nmz-multi-pick
(list (mew-nmz-expand-folder folder)) pattern nil 'single))
(defun mew-nmz-search-virtual (pattern flds &rest args)
(mew-nmz-setup)
(let* ((nmzdirs (mew-nmz-flds-to-indexs (or flds (list "*:*"))))
(fldmsgs (mew-nmz-multi-pick nmzdirs pattern nil))
(file (mew-make-temp-name))
(rttl 0)
fld)
(with-temp-buffer
(dolist (fldmsg fldmsgs)
(setq fld (car fldmsg))
(unless (mew-folder-localp fld)
(setq fld (mew-path-to-folder (mew-expand-folder fld))))
(insert (format "CD:%s\n" fld))
(dolist (msg (cdr fldmsg))
(insert msg "\n")
(setq rttl (1+ rttl))))
(mew-frwlet
mew-cs-text-for-read mew-cs-text-for-write
(write-region (point-min) (point-max) file nil 'no-msg)))
(list file rttl)))
;; codes
(defun mew-nmz-jump-message ()
"Jump to physical folder and message from virtual folder
or jump to virtual folder from physical folder."
(interactive)
(let ((disp (mew-sinfo-get-disp-msg))
fld msg)
(cond
((mew-thread-p)
(mew-summary-goto-message)
(setq fld (or (mew-vinfo-get-original-folder)
(mew-vinfo-get-physical-folder)))
(setq msg (mew-summary-message-number)))
((mew-virtual-p)
(mew-summary-goto-message)
(setq fld (mew-summary-folder-name))
(setq msg (mew-summary-message-number)))
(t
(setq fld (mew-summary-folder-name))
(setq msg (mew-summary-message-number))
(save-excursion
(let ((regex (format "\r %s %s[^0-9]" (regexp-quote fld) msg)))
(setq fld (catch 'detect
(dolist (buf (delq (current-buffer) (buffer-list)))
(set-buffer buf)
(save-excursion
(when (and (mew-virtual-p)
(or (re-search-forward regex nil t)
(re-search-backward regex nil t)))
(throw 'detect (buffer-name buf)))))
nil))))))
(if (not fld)
(message "Nothing to do")
(mew-nmz-goto-folder-msg fld msg nil disp)
(message "Jump to %s/%s" fld msg))))
(defun mew-nmz-mknmz-lang-arg ()
(when (boundp 'current-language-environment)
(let* ((env current-language-environment)
(alist mew-nmz-mknmz-lang-alist)
(lang (nth 1 (assoc env alist))))
(if lang (format "--indexing-lang=%s" lang)))))
;; "Make Index" functions.
(defun mew-nmz-mknmz (&optional fld all disp)
"Make namazu index for mew-nmz.
If executed with '\\[universal-argument]', make indices without the check of timestamp files.
If executed with '\\[universal-argument] 0', remove indices before make index."
(interactive
(list (directory-file-name
(mew-input-folder (mew-sinfo-get-case)
(or (mew-sinfo-get-folder) mew-inbox-folder)))
nil))
(save-excursion
(let ((msgenb (or (interactive-p)
(eq this-command 'mew-summary-make-index-folder)
disp))
(force (and current-prefix-arg
(not (eq current-prefix-arg 0))))
(remove (eq current-prefix-arg 0))
(flddir (mew-expand-folder fld))
(nmzdir (mew-nmz-expand-folder fld))
(bufname (format "%s*Mew* mknmz*%s"
(if (memq mew-debug '(namazu t)) "" " ")
fld))
(args mew-nmz-prog-mknmz-args)
(procname (concat mew-nmz-prog-mknmz "-" fld))
(procname2 (concat mew-nmz-prog-gcnmz "-" fld))
(incfile (and mew-nmz-prog-mknmz-include
(expand-file-name mew-nmz-prog-mknmz-include)))
(tmpfile (mew-make-temp-name))
flist continue)
(unless fld
(setq fld (directory-file-name
(mew-input-folder (mew-sinfo-get-case) (mew-sinfo-get-folder)))))
(cond
((not (mew-which-exec mew-nmz-prog-mknmz))
(message "Please install mknmz"))
((or (mew-folder-virtualp fld) (mew-nmz-skip-folder-p fld))
(and msgenb (message "Cannot make namazu index in %s" fld))
(setq continue t))
((or (get-process procname) (get-process procname2))
(and msgenb (message "Detect running mknmz/gcnmz process in %s" fld))
(setq continue t))
((and (not remove) (not force) (mew-nmz-index-new-p fld))
(and msgenb (message "%s has a newer namazu index" fld))
(setq continue t))
((and (not remove) (file-exists-p (expand-file-name "NMZ.lock2" nmzdir)))
(message "Something error in %s's index" fld)
(setq continue t))
((not (setq flist (mew-dir-messages (file-chase-links flddir)
nil 'full)))
(and msgenb (message "%s has no message" fld))
(mew-nmz-index-delete nmzdir)
(setq continue t))
((and flddir nmzdir (file-directory-p flddir))
(with-temp-buffer
(dolist (file flist)
(insert file "\n"))
(mew-frwlet
mew-cs-autoconv mew-cs-text-for-write
(write-region (point-min) (point-max) tmpfile nil 'nomsg)))
(setq args (delq nil
(append args
(list "--no-encode-uri"
;; "--mailnews"
(mew-nmz-mknmz-lang-arg)
(when (and incfile (file-exists-p incfile))
(format "--include=%s" incfile))
(format "--target-list=%s" tmpfile)
;; (format "--exclude=%s"
;; (expand-file-name ".+/" flddir))
(format "--output-dir=%s" nmzdir)))))
;; flddir))))
(unless (file-directory-p nmzdir)
(mew-make-directory nmzdir))
(when remove
(mew-nmz-index-delete nmzdir))
(set-buffer (get-buffer-create bufname))
(erase-buffer)
;; folder set
(and msgenb (message "Namazu indexing for %s..." fld))
(insert (format "mew-mknmz-prog: %s\nmew-mknmz-args: %s\n"
(mew-which-exec mew-nmz-prog-mknmz)
(mapconcat 'identity args " ")))
(mew-nmz-timestamp-new fld)
(mew-piolet
mew-cs-autoconv mew-cs-text-for-write
(setq mew-nmz-mknmz-process
(apply (function start-process)
procname (current-buffer) mew-nmz-prog-mknmz args)))
(setq mew-nmz-mknmz-process-folder fld)
(setq mew-nmz-mknmz-process-file tmpfile)
(set-process-sentinel mew-nmz-mknmz-process 'mew-nmz-mknmz-sentinel)
(when (and mew-nmz-mknmz-use-mode-line
fld (get-buffer fld) (buffer-name (get-buffer fld)))
(save-excursion
(set-buffer (get-buffer fld))
(setq mode-line-buffer-identification mew-nmz-line-id)
(set-buffer-modified-p nil)))))
(when (and continue all mew-nmz-mknmz-all-folders)
(mew-nmz-mknmz-continue-with-timer)))))
(defun mew-nmz-mknmz-continue-with-timer ()
(unless mew-nmz-mknmz-continue-timer
(setq mew-nmz-mknmz-continue-timer
(run-at-time mew-nmz-mknmz-timer-interval nil 'mew-nmz-mknmz-continue))))
(defun mew-nmz-mknmz-continue ()
(when mew-nmz-mknmz-continue-timer
(cancel-timer mew-nmz-mknmz-continue-timer)
(setq mew-nmz-mknmz-continue-timer nil))
(setq mew-nmz-mknmz-all-folders (cdr mew-nmz-mknmz-all-folders))
(if mew-nmz-mknmz-all-folders
(mew-nmz-mknmz (car mew-nmz-mknmz-all-folders) 'all)
(ding)
(message "All mknmz done")))
(defun mew-nmz-mknmz-sentinel (process event)
(save-excursion
(set-buffer (process-buffer process))
(let* ((fld mew-nmz-mknmz-process-folder)
(nmzdir (mew-nmz-expand-folder fld))
msg success)
(when (and (file-exists-p mew-nmz-mknmz-process-file)
(file-writable-p mew-nmz-mknmz-process-file))
(delete-file mew-nmz-mknmz-process-file))
(goto-char (point-min))
(if (search-forward-regexp "^ERROR:.*$" nil t)
(progn
(setq msg (format "Mew mknmz (%s)...%s" fld (match-string 0)))
(condition-case nil
(progn
(mew-nmz-index-delete nmzdir 'tmpfiles)
(delete-file (expand-file-name "NMZ.lock2" nmzdir))
(delete-file (expand-file-name "NMZ.stamp.new" nmzdir)))
(error nil)))
(setq success t)
(mew-nmz-timestamp-rename fld)
(setq msg (format "Namazu indexing %s...done" fld))
(when mew-nmz-setup-p
(setq fld (mew-nmz-case-folder-normalize fld))
(unless (mew-nmz-folder-to-nmzdir fld)
(setq mew-nmz-fld-index-alist
(cons (cons fld nmzdir) mew-nmz-fld-index-alist))
(setq mew-nmz-url-fld-alist
(cons (cons (mew-expand-folder fld) fld)
mew-nmz-url-fld-alist))
(mew-nmz-cache-save))))
(setq mew-nmz-mknmz-process nil)
(setq mew-nmz-mknmz-process-folder nil)
(when (and mew-nmz-mknmz-use-mode-line
fld (get-buffer fld) (buffer-name (get-buffer fld)))
(save-excursion
(set-buffer (get-buffer fld))
(setq mode-line-buffer-identification
(if (fboundp 'mew-mode-line-id)
(mew-mode-line-id)
mew-mode-line-id))
(set-buffer-modified-p nil)))
(set-buffer-modified-p nil)
(unless (memq mew-debug '(namazu t))
(kill-buffer (current-buffer)))
(message "%s" msg)
(when (and success (mew-nmz-gcnmz-folder-p fld))
(mew-nmz-gcnmz fld nmzdir))
(when mew-nmz-mknmz-all-folders
(mew-nmz-mknmz-continue-with-timer)))))
(defun mew-nmz-gcnmz (&optional fld nmzdir)
"Garbage collection for mew-nmz."
(interactive
(list (directory-file-name
(mew-input-folder (mew-sinfo-get-case)
(or (mew-sinfo-get-folder) mew-inbox-folder)))
nil))
(unless nmzdir
(setq nmzdir (mew-nmz-expand-folder fld)))
(if (and (mew-which-exec mew-nmz-prog-gcnmz)
(file-directory-p nmzdir)
(file-exists-p (expand-file-name "NMZ.i" nmzdir)))
(let ((buf (get-buffer-create
(format "%s*Mew* gcnmz*%s"
(if (memq mew-debug '(namazu t)) "" " ")
fld)))
(procname (concat mew-nmz-prog-gcnmz "-" fld))
(args `("--no-backup" ,nmzdir))
process)
(save-excursion
(set-buffer buf)
(erase-buffer)
(setq mew-nmz-mknmz-process-folder fld)
(message "Mew gcnmz (%s)..." mew-nmz-mknmz-process-folder)
(insert (format "mew-gcnmz-prog: %s\nmew-gcnmz-args: %s\n"
(mew-which-exec mew-nmz-prog-gcnmz)
(mapconcat 'identity args " ")))
(setq process
(apply (function start-process)
procname (current-buffer) mew-nmz-prog-gcnmz args))
(set-process-sentinel process 'mew-nmz-gcnmz-sentinel)
(when (and mew-nmz-mknmz-use-mode-line
fld (get-buffer fld) (buffer-name (get-buffer fld)))
(save-excursion
(set-buffer (get-buffer fld))
(setq mode-line-buffer-identification mew-nmz-gcnmz-line-id)
(set-buffer-modified-p nil)))))
(when (interactive-p)
(message "gcnmz cannot run on %s" fld))))
(defun mew-nmz-gcnmz-sentinel (process event)
(when (buffer-name (process-buffer process))
(set-buffer (process-buffer process))
(let ((fld mew-nmz-mknmz-process-folder))
(if (and fld event (stringp event) (string= event "kill"))
(progn
(message "Mew gcnmz (%s)...kill from user" fld)
(condition-case nil
(mew-nmz-index-delete (mew-nmz-expand-folder fld) 'tmpfiles)
(error nil)))
(message "Mew gcnmz (%s)...done" fld))
(when (and mew-nmz-mknmz-use-mode-line
fld (get-buffer fld) (buffer-name (get-buffer fld)))
(save-excursion
(set-buffer (get-buffer fld))
(setq mode-line-buffer-identification
(if (fboundp 'mew-mode-line-id)
(mew-mode-line-id)
mew-mode-line-id))
(set-buffer-modified-p nil)))
(unless (memq mew-debug '(namazu t))
(kill-buffer (current-buffer))))))
(defun mew-nmz-mknmz-kill-process ()
"Kill the all processes of mknmz."
(interactive)
(when mew-nmz-mknmz-continue-timer
(cancel-timer mew-nmz-mknmz-continue-timer)
(setq mew-nmz-mknmz-continue-timer nil))
(let ((proc-list (process-list))
(regex1 (concat "^" mew-nmz-prog-mknmz "-"))
(regex2 (concat "^" mew-nmz-prog-gcnmz "-"))
buf kill)
(dolist (process proc-list)
(cond
((string-match regex1 (process-name process))
;; mknmz
(setq buf (process-buffer process))
(when (buffer-name buf)
(save-excursion
(set-buffer buf)
(set-process-sentinel process 'ignore)
(goto-char (point-max))
(insert "\nERROR: Kill from user.\n")
(kill-process process)
(mew-nmz-mknmz-sentinel process "kill")
(setq kill t))))
((string-match regex2 (process-name process))
;; gcnmz
(setq buf (process-buffer process))
(when (buffer-name buf)
(set-process-sentinel process 'ignore)
(kill-process process)
(mew-nmz-gcnmz-sentinel process "kill")
(setq kill t)))))
(setq mew-nmz-mknmz-all-folders nil)
(when (interactive-p)
(if kill
(message "All process of mknmz killed")
(message "No process of mknmz")))))
(defun mew-nmz-mknmz-get-all-folders ()
(let ((protos (delq mew-folder-virtual (copy-sequence mew-folder-prefixes)))
(allcases (or mew-config-cases '("")))
flist cases donecases flds fld dir)
(message "mew-nmz getting all folders...")
(dolist (proto protos)
(setq flds nil)
(setq cases allcases)
(setq donecases nil)
(dolist (case cases)
(if (or (string= case mew-case-default)
(string= case ""))
(setq case (mew-nmz-case-normalize proto))
(setq case (mew-nmz-case-normalize
(concat case ":" proto))))
(unless (member case donecases)
(setq donecases (cons case donecases))
(setq flds
(cond
((mew-folder-imapp proto)
(mapcar (lambda (x) (car x))
(mew-imap-folder-alist case)))
((mew-folder-nntpp proto)
(mapcar (lambda (x) (car x))
(mew-nntp-folder-alist case)))
((mew-folder-popp proto)
(mapcar (lambda (x) (car x))
(mew-pop-folder-alist)))
(t
(mapcar (lambda (x) (car x))
(mew-local-folder-alist)))))
(setq case (if (string= case "")
""
(concat case ":")))
(dolist (fld flds)
(setq fld (concat case fld))
(setq dir (mew-expand-folder fld))
(when (and dir
(file-exists-p dir)
(file-directory-p dir)
(file-exists-p (expand-file-name mew-summary-touch-file dir)))
(setq flist (cons (directory-file-name fld) flist)))))))
(prog1
(setq flist (nreverse flist))
(with-temp-buffer
(dolist (fld flist)
(unless (mew-nmz-skip-folder-p fld)
(insert (format "%s\t%s\t%s\n"
fld
(mew-expand-folder fld)
(mew-nmz-expand-folder fld))))
(setq flist (cdr flist)))
(mew-frwlet
mew-cs-text-for-read mew-nmz-mknmz-index-file-coding-system
(write-region (point-min) (point-max)
(expand-file-name mew-nmz-mknmz-index-file mew-conf-path)
nil 'nomsg)))
(message "mew-nmz getting all folders...done"))))
(defun mew-nmz-mknmz-all-folders (&optional args)
"Make namazu index all folders."
(interactive "P")
(setq args (or args current-prefix-arg))
(when (or (null mew-nmz-mknmz-all-folders)
(and mew-nmz-mknmz-all-folders
(prog1
(y-or-n-p "Another mew-nmz-mknmz-all-folders() detect. Kill it? ")
(mew-nmz-mknmz-kill-process))))
(when (y-or-n-p (format "Make index in all %s? "
(if args "folders" "indexed folders")))
(let (alist flist)
(if args
(progn
;; all exist folder
(mew-nmz-cleanup 'remove)
(setq flist (mew-nmz-mknmz-get-all-folders)))
;; all indexed folder
(mew-nmz-setup)
(setq alist mew-nmz-fld-index-alist)
(while alist
(setq flist (cons (car (car alist)) flist))
(setq alist (cdr alist))))
(setq flist (nreverse flist))
;; for mew-nmz-mknmz()
(setq current-prefix-arg nil)
(setq mew-nmz-mknmz-all-folders flist)
(when flist
(mew-nmz-mknmz (car flist) 'all))))))
(defun mew-nmz-mknmz-save-mewmknmz ()
"Save the information for mknmz."
(interactive)
(mew-nmz-cleanup 'remove)
(mew-nmz-setup)
(mew-nmz-mknmz-get-all-folders))
(defun mew-nmz-mark-unindexed ()
"Mark unindexed messages."
(interactive)
(mew-summary-only
(if (mew-summary-exclusive-p)
(save-excursion
(if (and (mew-summary-mark-collect
mew-nmz-mark-unindexed (point-min) (point-max))
(y-or-n-p (format "Unmark '%c'? " mew-nmz-mark-unindexed)))
(mew-mark-undo-mark mew-nmz-mark-unindexed 'nomsg))
(let* ((ufname
(expand-file-name "NMZ.field.uri"
(mew-nmz-expand-folder (buffer-name))))
(mmsgs 0)
(umsgs 0)
msgnums)
(if (not (file-exists-p ufname))
(message "%s has no index file" (buffer-name))
(with-temp-buffer
(message "checking %s..." (file-name-nondirectory ufname))
(insert-file-contents ufname)
(while (re-search-forward "/\\([0-9]+\\)$" nil t)
(setq msgnums (cons (string-to-number (match-string 1)) msgnums))))
(message "checking %s..." (buffer-name))
(goto-char (point-min))
(while (not (eobp))
(if (and (mew-sumsyn-match mew-regex-sumsyn-short)
(not (memq (string-to-number (mew-sumsyn-message-number)) msgnums))
(not (mew-in-decode-syntax-p)))
(progn
(setq umsgs (1+ umsgs))
(when (mew-summary-markable)
(mew-summary-mark-as mew-nmz-mark-unindexed)
(setq mmsgs (1+ mmsgs)))))
(forward-line))
(cond
((= umsgs 1)
(message "%d message does not have index, %d marked"
umsgs mmsgs))
((> umsgs 1)
(message "%d messages do not have index, %d marked"
umsgs mmsgs))
(t
(message "all messages have index")))))))))
;; "search Message-ID" functions.
(defun mew-nmz-search-parent (&optional child mid)
"Search *parent* message and jump to that.
If executed with '\\[universal-argument]', search *child* message."
(interactive "P")
(when (memq major-mode '(mew-summary-mode mew-virtual-mode))
(mew-summary-goto-message))
(let ((fld (mew-summary-folder-name))
(msg (mew-summary-message-number))
(idh (list (list mew-in-reply-to: mew-references:)
(list mew-message-id:)))
(message (if child "children" "parent"))
(refilefld (copy-sequence mew-nmz-search-parent-folder))
(proto (or (mew-proto-to-refile (or (mew-sinfo-get-folder)
(mew-minfo-get-summary)
"+"))
"+"))
(case (mew-sinfo-get-case))
refiledir mess ref pid pos killbuff)
(if mid
(setq pid (list mid) idh nil)
(if (not (or msg (mew-syntax-number)))
(message "No message here")
(save-excursion
(mew-nmz-setup)
(mew-summary-display)
(if (setq mess (mew-cache-hit fld msg))
(set-buffer mess)
(setq mess (generate-new-buffer mew-buffer-prefix))
(setq killbuff t)
(set-buffer mess)
(mew-erase-buffer)
(mew-insert-message
fld msg mew-cs-text-for-read mew-header-reasonable-size))
(let ((mew-inherit-refile-proto proto)
(mew-inherit-refile-case case))
(setq refilefld (append (car (mew-refile-guess nil t)) refilefld)))
(if child
(setq idh (car (cdr idh)))
(setq idh (car idh)))
(dolist (rh idh)
(setq ref (mew-header-get-value rh))
(while (and ref (string-match "<\\([^>]+\\)>" ref))
(setq pid (cons (concat "\"" (match-string 1 ref) "\"") pid))
(setq refilefld
(cons (nth 1 (assoc (car pid) mew-refile-msgid-alist)) refilefld))
(setq ref (substring ref (match-end 0)))))
(setq refilefld (cons fld refilefld))
(setq refilefld (mew-uniq-list (delete nil refilefld)))
(setq refiledir
(delete nil (mapcar
(lambda (x)
(mew-nmz-expand-folder x))
refilefld))))))
(when killbuff (mew-kill-buffer mess))
(if (null pid)
(message "No required header")
(if (mew-syntax-number)
(while (not (mew-summary-message-number))
(forward-line -1)))
(mew-sinfo-set-ret-pos (point))
(let ((pattern1 "")
(pattern2 "")
(addpattern (if child "+in-reply-to:" "+message-id:"))
(range nil))
(if (not child)
(setq pattern1 (concat addpattern (car pid)))
(setq pattern1 (concat addpattern (car pid)))
(setq addpattern "+references:")
(setq pattern1 (concat pattern1 " | " addpattern (car pid))))
(setq pid (delete (car pid) pid))
(while pid
(if (> (length (concat pattern2 addpattern (car pid)))
mew-nmz-query-max-length)
(setq pid nil)
(setq pattern2 (concat pattern2 addpattern (car pid)))
(setq addpattern (if child " | +references:" " | +message-id:"))
(setq pid (delete (car pid) pid))))
(message "Searching %s..." message)
(let ((pattern (list pattern1 pattern2)))
(while (and (null range) pattern)
(if mid
()
(message "Searching %s...%s" message (mew-join ", " refilefld))
(setq range (mew-nmz-multi-pick refiledir (car pattern)))
(when range
(catch 'detect
(dolist (ref refilefld)
(if (null (setq idh (assoc ref range)))
()
(setq fld (car idh))
(if child
(setq range (cdr idh))
(setq range (nreverse (cdr idh))))
(throw 'detect t)))
nil)))
(unless range
;; all folder search
(message "Searching %s...all folders" message)
(setq range (mew-nmz-multi-pick
(mew-nmz-expand-folder-regexp "*:*")
(car pattern) 'catch))
(if (null range)
(setq pattern (cdr pattern))
(setq fld (car (car range)))
(setq range (cdr (car range)))
(if (not child) (setq range (nreverse range)))
))))
(if (null range)
(message "No message found")
(when (or (and (mew-thread-p)
(string= (mew-summary-folder-name) fld))
(and (mew-virtual-p)
(not (mew-thread-p))))
(save-excursion
(goto-char (point-min))
(when (re-search-forward
(concat "\r \\(" (regexp-quote fld) "\\)? +" (car range) " ") nil t)
(setq fld (buffer-name))
(goto-char (match-beginning 0))
(beginning-of-line)