This file is indexed.

/usr/share/emacs/site-lisp/mew/mew-summary4.el is in mew-beta 7.0.50~6.7+0.20150818-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
;;; mew-summary4.el --- Summary mode for Mew

;; Author:  Kazu Yamamoto <Kazu@Mew.org>
;; Created: Oct  2, 1996

;;; Code:

(require 'mew)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Variables
;;;

(defvar mew-last-shell-command "")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Switching to folder
;;;

(defun mew-summary-switch-to-folder (case:folder &optional func)
  (let ((ofolder (mew-summary-folder-name 'ext)))
    (cond
     ((get-buffer case:folder)
      (switch-to-buffer case:folder)
      (mew-set-buffer-cs mew-cs-m17n)
      (unless (mew-folder-virtualp case:folder) (mew-summary-folder-cache-load))
      (unless (string= ofolder case:folder) (mew-window-configure 'summary))
      nil) ;; existing folder
     (t
      (funcall (or func 'switch-to-buffer) (get-buffer-create case:folder))
      (kill-all-local-variables)
      (mew-set-buffer-cs mew-cs-m17n)
      (mew-buffers-setup case:folder)
      (let* ((case (mew-case:folder-case case:folder))
	     (folder (mew-case:folder-folder case:folder))
	     (inboxp (string= folder (mew-proto-inbox-folder folder (or case mew-case)))))
	(mew-sinfo-set-case case)
	(mew-sinfo-set-folder folder)
	(mew-sinfo-set-inboxp inboxp))
      (if (mew-folder-virtualp case:folder)
	  (mew-virtual-mode)
	(mew-summary-mode)
	(if mew-summary-trace-directory (cd (mew-expand-folder case:folder)))
	(mew-summary-folder-cache-load))
      (mew-window-configure 'summary)
      t)))) ;; new-folder

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Moving to folder
;;;

(defun mew-summary-goto-folder (&optional goend)
  "Go to the folder which you specify.  If executed with
'\\[universal-argument]', the cursor always goes to the bottom of
Summary mode."
  (interactive "P")
  (let* ((proto (mew-proto-to-go (mew-summary-folder-name 'ext)))
	 (case1 (car (mew-summary-case-proto)))
	 (inbox (mew-proto-inbox-folder	proto case1))
	 (case:folder (mew-input-folder case1 inbox))
	 case folder buf win frame folder-alist)
    (if (null case:folder)
	(message "The folder does not exist")
      (setq case (mew-case:folder-case case:folder))
      (setq folder (mew-case:folder-folder case:folder))
      (cond
       ((mew-folder-imapp folder)
	(setq folder-alist (mew-imap-folder-alist case))
	;;
	(unless (or (assoc folder folder-alist)
		    (assoc (concat folder (mew-imap-separator case)) folder-alist))
	  (message "\"%s\" does not exist. %s" case:folder
		   (mew-substitute-for-summary "Type '\\[universal-argument]\\[mew-status-update]' to collect IMAP folders"))
	  (setq case:folder nil)))
       ((mew-folder-nntpp folder)
	(unless (assoc folder (mew-nntp-folder-alist case))
	  (message "\"%s\" does not exist. %s" case:folder
		   (mew-substitute-for-summary "Type '\\[universal-argument]\\[mew-status-update]' to collect newsgroups"))
	  (setq case:folder nil))))
      (when case:folder
	(when mew-use-other-frame-for-summary
	  (if (setq buf (get-buffer case:folder))
	      (if (setq win (get-buffer-window buf 0))
		  (progn
		    (setq frame (window-frame win))
		    (raise-frame frame)
		    (select-frame frame)
		    ;; Ensure, if possible, that frame gets input focus.
		    (mew-focus-frame frame))
		(select-frame (make-frame)))
	    (select-frame (make-frame))))
	(mew-summary-visit-folder case:folder goend)))))

(defun mew-summary-visit-folder (folder &optional goend no-ls)
  (let ((dir (mew-expand-folder folder))
	new-folder scanp)
    (cond
     ((mew-folder-virtualp folder)
      (if (get-buffer folder)
	  (if (mew-virtual-thread-p folder)
	      (if (mew-thread-cache-valid-p folder)
		  (mew-summary-switch-to-folder folder)
		(message "%s is old" folder))
	    (mew-summary-switch-to-folder folder))
        (message "No such virtual folder: %s" folder)))
     (t ;; local/remote folders
      (if (null dir)
	  (message "Folder is wrong")
	(cond
	 ((mew-folder-remotep (mew-case:folder-folder folder))
	  (unless (file-directory-p dir)
	    (mew-make-directory dir))
	  (setq scanp t))
	 (t ;; +, ~, /, drive letter
	  (if (file-directory-p dir)
	      (setq scanp t)
	    (message "No such folder %s" folder))))
	(when scanp
	  (if no-ls
	      (progn
		(mew-summary-switch-to-folder folder)
		(if goend (goto-char (point-max)))
		(if (pos-visible-in-window-p (point-min))
		    (mew-summary-cook-window)))
	    (setq new-folder (mew-summary-switch-to-folder folder))
	    (if (and (mew-summary-ls nil (or goend new-folder))
		     (pos-visible-in-window-p (point-min)))
		(mew-summary-cook-window)))))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Going to a line
;;;

(defun mew-summary-goto-line (&optional arg)
  "Jump to a line according to the number which you input.
If 'mew-summary-goto-line-then-display' is non-nil,
the message is then displayed."
  (interactive "P")
  (if arg
      (let ((msg (read-string "Message No.: " "")))
	(while (not (string-match mew-regex-message-files3 msg))
	  (setq msg (read-string "Message No.: " "")))
	(when (mew-summary-search-msg msg)
	  (if mew-summary-goto-line-then-display
	      (mew-summary-display))))
    (let ((line (string-to-number (read-string "Line No.: " ""))))
      (when (/= line 0)
	(goto-char (point-min)) (forward-line (1- line))
	(if mew-summary-goto-line-then-display
	    (mew-summary-display))))))

(defun mew-summary-goto-original-message ()
  "Go to the original message in the original Summary mode"
  (interactive)
  (cond
   ((mew-summary-p)
    (message "This is the original"))
   ((mew-virtual-p)
    (let ((folder (mew-folder-path-to-folder (mew-summary-folder-name) 'has-proto))
	  (msg (mew-summary-message-number)))
      (when folder
	(mew-summary-visit-folder folder nil 'no-ls)
	(if (mew-summary-search-msg msg)
	    (mew-summary-display)
	  (message "No original message found")))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Moving to Message mode
;;;

(defun mew-summary-goto-msg-mode ()
  "Go to Header mode."
  (interactive)
  (let (msgp)
    (with-current-buffer (window-buffer (next-window))
      (if (mew-message-p) (setq msgp t)))
    (if msgp
	(other-window 1)
      (message "No Message mode displayed"))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Moving to +draft
;;;

(defun mew-max-draft-buffer ()
  (let* ((draft-dir (file-name-as-directory mew-draft-folder))
	 (regex (mew-folder-regex draft-dir))
         (bufs (mew-buffer-list regex))
	 (msgregex (format "\\([0-9]+\\)\\(%s\\)?$" mew-suffix))
         nums n)
    (setq nums (mapcar (lambda (x) (string-match msgregex x) (string-to-number (mew-match-string 1 x))) bufs))
    (dolist (num nums)
      (if (or (null n) (< n num))
	  (setq n num)))
    (and n (format "%s%d%s" draft-dir n (if mew-use-suffix mew-suffix "")))))

(defun mew-summary-jump-to-draft-buffer ()
  "Jump to one of drafts if exists."
  (interactive)
  (let* ((draft (mew-max-draft-buffer)) buf)
    (if (null draft)
	(message "No draft buffer exists!")
      (setq buf (mew-input-draft-buffer draft))
      (if (get-buffer buf)
	  (switch-to-buffer buf)
	(message "No such draft buffer!")))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Moving to top and bottom
;;;

(defun mew-summary-jump-top ()
  "Go to the beginning of this Summary mode.
If 'mew-summary-jump-top-then-display' is non-nil,
the top message is then displayed."
  (interactive)
  (if mew-use-push-mark (mew-push-mark))
  (goto-char (point-min))
  (if mew-summary-jump-top-then-display
      (mew-summary-display)))

(defun mew-summary-jump-bottom ()
  "Go to the end of this Summary mode.
If 'mew-summary-jump-bottom-then-display' is non-nil,
the top message is then displayed."
  (interactive)
  (if mew-use-push-mark (mew-push-mark))
  (goto-char (point-max))
  (if (and (mew-summary-exclusive-p 'no-msg)
	   (not (bobp))
	   (mew-sinfo-get-disp-msg))
      (forward-line -1))
  (if mew-summary-jump-bottom-then-display
      (mew-summary-display)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Moving to the marker
;;;

(defun mew-summary-exchange-point ()
  "\\<mew-summary-mode-map>Get back to the position before typing '\\[mew-summary-retrieve]' or '\\[mew-summary-ls]'."
  (interactive)
  (mew-summary-only
   (let ((pos (mew-sinfo-get-ret-pos)))
     (if pos (goto-char pos)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Searching
;;;

(defun mew-summary-isearch-forward (&optional arg)
  "Incremental search forward in Message mode."
  (interactive "P")
  (let ((cwin (get-buffer-window (current-buffer)))
	(mwin (get-buffer-window (mew-buffer-message))))
    (if (not mwin)
	(message "No message is displayed")
      (select-window mwin)
      (unwind-protect
	  (progn
	    (widen)
	    (isearch-forward arg)
	    (mew-message-narrow-to-page))
	(select-window cwin)))))

(defun mew-summary-isearch-backward (&optional arg)
  "Incremental search backward in Message mode."
  (interactive)
  (let ((cwin (get-buffer-window (current-buffer)))
	(mwin (get-buffer-window (mew-buffer-message))))
    (if (not mwin)
	(message "No message is displayed")
      (select-window mwin)
      (unwind-protect
	  (progn
	    (widen)
	    (isearch-backward arg)
	    (mew-message-narrow-to-page))
	(select-window cwin)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Pipe
;;;

(defun mew-summary-pipe-message (prefix command)
  "Send the content of Message buffer to a command via pipe.
If called with '\\[universal-argument]', the body of the message
\(excluding its header) is sent."
  (interactive
   (list current-prefix-arg
	 (read-string "Shell command on message: " mew-last-shell-command)))
  (mew-summary-display 'redisplay)
  (when (or (not mew-ask-pipe)
            (y-or-n-p "Send this message to pipe? "))
    (with-current-buffer (mew-buffer-message)
      (save-restriction
	(widen)
	(if (string= command "") (setq command mew-last-shell-command))
	(goto-char (point-min)) ; perhaps this line won't be necessary
	(if prefix (search-forward "\n\n"))
	(let ((max-mini-window-height 1))
	  (shell-command-on-region (point) (point-max) command nil))
	(setq mew-last-shell-command command)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Print
;;;

(defun mew-summary-print (&optional arg)
  "Print the content of Message mode according to 'mew-print-function'.
If called with '\\[universal-argument]', you can specify a printer name."
  (interactive "P")
  (mew-summary-display 'redisplay)
  (let ((printer-name (if arg
			  (read-string "Printer name: ")
			printer-name))
	have-header str)
    (with-current-buffer (mew-buffer-message)
      (save-restriction
	(widen)
	(setq have-header (mew-msghdr-p))
	(setq str (buffer-substring (point-min) (point-max)))))
    (when (y-or-n-p "Print this message? ")
      (with-temp-buffer
	(insert str)
	(if have-header
	    (mew-header-delete-other-lines mew-field-for-printing))
	(funcall mew-print-function)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Saving a message to a file with header decoded
;;;

(defun mew-summary-store (&optional askcs)
  "Saving a buffer of Message mode to a file.
If executed with '\\[universal-argument]', coding-system is asked."
  (interactive "P")
  (mew-summary-display 'redisplay)
  (let* ((file (mew-summary-input-file-name))
	 (doit (if (file-exists-p file)
		   (if (y-or-n-p (format "File exists. Override it? "))
		       t
		     nil)
		 t)))
    (if (not doit)
	(message "Not saved")
      (let ((writecs (if askcs
			 (read-coding-system "Coding-system: ")
		       (default-value 'buffer-file-coding-system))))
	(with-current-buffer (mew-buffer-message)
	  (mew-frwlet mew-cs-dummy writecs
	    ;; do not specify 'no-msg
	    (write-region (point-min) (point-max) file)))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; X-Face:
;;;

(defun mew-summary-x-face ()
  "Display xface."
  (interactive)
  (mew-summary-msg
   (let ((file (mew-make-temp-name)) xface)
     (with-current-buffer (mew-buffer-message)
       (setq xface (mew-header-get-value mew-x-face:)))
     (when xface
       (with-temp-buffer
	 (insert xface)
	 (mew-x-face-compface-to-xbm)
	 (mew-frwlet mew-cs-dummy mew-cs-text-for-write
	   (write-region (point-min) (point-max) file nil 'no-msg)))
       (mew-mime-image-ext file)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Calling a command
;;;

(defun mew-summary-cmd-msg ()
  "Executing an external command specifying this message as an
argument."
  (interactive)
  (mew-summary-msg-or-part
   (let* ((fld (mew-summary-folder-name))
	  (msg (mew-summary-message-number))
	  (file (mew-expand-msg fld msg))
	  (cmd-args (mew-input-command))
	  (cmd (car cmd-args))
	  (args (nconc (cdr cmd-args) (list file))))
     (message "Executing %s for %s..." cmd msg)
     (apply 'call-process cmd nil nil nil args)
     (message "Executing %s for %s...done" cmd msg))))

(defun mew-summary-cmd-msgs ()
  "Executing an external command specifying messages
marked with '*' as arguments."
  (interactive)
  (mew-summary-multi-msgs
   (let* ((cmd-args (mew-input-command))
	  (cmd (car cmd-args))
	  (args (nconc (cdr cmd-args) FILES)))
     (message "Executing %s ..." cmd)
     (apply 'call-process cmd nil nil nil args)
     (message "Executing %s ...done" cmd))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Citation
;;;

(defun mew-summary-cite (&optional arg)
  "Cite this message to one of drafts."
  (interactive "P")
  (let ((draft (mew-max-draft-buffer)) buf)
    (if (null draft)
	(message "No draft buffer exists!")
      (setq buf (mew-input-draft-buffer draft))
      (if (get-buffer buf)
	  (with-current-buffer buf
	    (mew-draft-cite arg))
	(message "No such draft buffer!")))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Flushing the queue
;;;

(defun mew-summary-send-message (&optional arg)
  "If in +queue, send the messages in +queue.
If in +postq, post the messages in +postq.
If in %queue, process the jobs in %queue.
Otherwise, flush the default queue.
If executed with '\\[universal-argument]', you can set the sending case."
  (interactive "P")
  (if (mew-folder-imap-queuep)
      (progn
	(mew-window-configure 'summary)
	(mew-imap-flush-queue))
    (let* ((fld (mew-summary-folder-name 'ext))
	   (proto (mew-proto-to-flush fld))
	   qfld case)
      (if (or arg mew-ask-flush-case)
	  (setq case (mew-input-case mew-case "Queue"))
	(setq case mew-case))
      (if (or (mew-folder-queuep fld) (mew-folder-postqp fld))
	  (progn
	    (setq qfld fld)
	    (mew-window-configure 'summary))
	(setq qfld (mew-proto-queue-folder proto case)))
      (if (and mew-ask-flush-queue
	       (not (y-or-n-p (concat "Flush " qfld  "? "))))
	  (message "The queue is not flushed")
	(cond
	 ((mew-folder-postqp qfld)
	  (mew-nntp2-flush-queue case qfld))
	 (t
	  (mew-smtp-flush-queue case qfld)))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Unlocking
;;;

(defun mew-subprocess-init ()
  (add-hook 'kill-emacs-hook 'mew-subprocess-kill))

(defun mew-subprocess-clean-up ()
  (mew-summary-kill-subprocess t)
  (remove-hook 'kill-emacs-hook 'mew-subprocess-kil))

(defun mew-subprocess-kill ()
  (mew-summary-kill-subprocess t))

(defun mew-summary-kill-subprocess (&optional kill-ssx)
  "\\<mew-summary-mode-map>
Kill a process in Summary mode.
Sometime a process accidentally remains in Summary mode.
In this situation, you cannot execute '\\[mew-summary-retrieve]', '\\[mew-summary-ls]', nor '\\[mew-summary-exec]'.
Use this command to solve this problem.

If called with '\\[universal-argument]', all SSH processes, if
any, are killed."
  (interactive "P")
  (let ((process mew-summary-buffer-process)
	(disp-msg (mew-called-interactively-p))
	pros sentinel)
    (if kill-ssx
	(progn
	  (setq pros (process-list))
	  (dolist (pro pros)
	    (if (string-match "mew" (process-name pro))
		(delete-process pro)))
	  (if disp-msg (message "All SSH/SSL/TLS processes were killed")))
      (cond
       ((not (processp process))
	;; If you type "x" over SSH and type "C-g" to quit,
	;; refile information remains invisible.
	;; This command turns it visible.
	(mew-summary-visible-buffer (current-buffer))
	(if disp-msg (message "No process to kill. This buffer is unlocked anyway")))
       ((eq process t)
	;; Emacs is locking
	(if disp-msg (message "This buffer was unlocked")))
       ((memq (process-status process) '(open closed))
	;; Network process
	(setq sentinel (process-sentinel process))
	(if (fboundp sentinel)
	    (funcall sentinel process "killed by the user"))
	(delete-process process)
	(if disp-msg (message "The process was killed")))
       (t
	;; Local process or SSH/SSL/TLS
	(delete-process process)
	(if disp-msg (message "The process was killed")))))
    (mew-summary-unlock)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; De-composing with the old style
;;;

(defun mew-summary-unshar ()
  "Apply 'unshar' on messages marked with '*'."
  (interactive)
  (mew-summary-multi-msgs
   (if (y-or-n-p (format "Execute %s for these messages? " mew-prog-unshar))
       (let* ((default-directory (mew-summary-input-directory-name)))
	 (message "Executing %s..." mew-prog-unshar)
	 (apply 'call-process mew-prog-unshar nil nil nil FILES)
	 (message "Executing %s...done" mew-prog-unshar)))))

(defun mew-summary-uudecode ()
  "Apply 'uudecode' on messages marked with '*'."
  (interactive)
  (mew-summary-multi-msgs
   (cond
    ((not (mew-which-exec mew-prog-mime-decode))
     ())
    ((not (y-or-n-p "Uudecode these messages? "))
     ())
    (t
     (let ((dir (mew-summary-input-directory-name))
	   (fn nil)
	   (tmp (mew-make-temp-name))
	   (case-fold-search nil)
	   (files FILES) start)
       (with-temp-buffer
	 (mew-frwlet mew-cs-text-for-read mew-cs-text-for-write
	   (dolist (file files)
	     (mew-erase-buffer)
	     (mew-insert-file-contents file)
	     (goto-char (point-min))
	     (if (re-search-forward mew-eoh nil t)
		 (forward-line))
	     (setq start (point))
	     (goto-char (point-max))
	     (unless (bolp) (insert "\n"))
	     (write-region start (point-max) tmp 'append 'no-msg)))
	 (mew-erase-buffer)
	 (cd dir)
	 ;; mew-folder-local is dummy to let mewencode use
	 ;; the embedded filename
	 (call-process mew-prog-mime-decode tmp t nil
		       "-d" "-u" "-" mew-folder-local)
	 (mew-delete-file tmp)
	 (goto-char (point-min))
	 (if (not (looking-at "^filename: \\(.*\\)"))
	     (message "Failed to execute %s" mew-prog-mime-decode)
	   (setq fn (mew-match-string 1))
	   (setq fn (mew-summary-prog-exec mew-prog-compress "-df" "Z" fn))
	   (setq fn (mew-summary-prog-exec mew-prog-gzip "-df" "gz" fn))
	   (when (and (string-match "^\\(.*\\)\\.tar$" fn)
		      (y-or-n-p (format "Execute %s for %s? " mew-prog-tar fn)))
	     (message "Executing %s for %s..." mew-prog-tar fn)
	     (call-process mew-prog-tar nil nil nil "-xf" fn)
	     (message "Executing %s for %s...done" mew-prog-tar fn)))))))))

(defun mew-summary-prog-exec (prog opts suffix tarfile)
  (if (string-match (format "^\\(.*\\)\\.%s$" suffix) tarfile)
      (let ((basename (match-string 1 tarfile)))
	(if (not (y-or-n-p (format "Execute %s for %s? " prog tarfile)))
	    tarfile
	  (message "Executing %s for %s..." prog tarfile)
	  (call-process prog nil nil nil opts tarfile)
	  (message "Executing %s for %s...done" prog tarfile)
	  basename))
    tarfile))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; De-composing with the new style
;;;

(defun mew-summary-join ()
  "Concat Message/Partial fragments marked with '*' to an original
message."
  (interactive)
  (mew-summary-only
   (mew-summary-with-mewl
    (mew-summary-multi-msgs
     (let ((cfld (mew-summary-folder-name))
	   (folder (mew-input-burst-folder))
	   (tfile (mew-make-temp-name))
	   (targets FLD-MSG-LIST)
	   num ct med dbl vec len idx ttl TTL fid FID i
	   beg regex)
       (message "Joining...")
       (with-temp-buffer
	 (mew-set-buffer-multibyte t)
	 (insert "CD: " (mew-expand-folder2 cfld) "\n")
	 (let ((default-directory (mew-expand-folder cfld)))
	   (dolist (fld-msg targets)
	     (insert (mew-msg-get-filename (cdr fld-msg)) "\n")))
	 (mew-frwlet mew-cs-text-for-read mew-cs-text-for-write
	   (write-region (point-min) (point-max) tfile nil 'no-msg))
	 (mew-erase-buffer)
	 (call-process mew-prog-mewl nil t nil
		       "-b" mew-mail-path "-l" "0"
		       "-x" mew-suffix
		       "-i" tfile "-d" "content-type")
	 (mew-delete-file tfile)
	 (goto-char (point-min))
	 (while (not (eobp))
	   (if (not (looking-at "^\\([0-9]+\\)[ \t]*:[ \t]*"))
	       (forward-line)
	     (setq num (mew-match-string 1))
	     (setq med (match-end 0))
	     (forward-line)
	     (mew-header-goto-next)
	     (setq ct (mew-param-decode
		       (mew-buffer-substring med (1- (point)))))
	     (setq dbl (cons (cons num ct) dbl))))
	 (setq len (length dbl))
	 (setq vec (make-vector len nil))
	 (dolist (ent dbl)
	   (setq num (car ent))
	   (setq ttl (mew-syntax-get-param ent "total"))
	   (setq fid (mew-syntax-get-param ent "id"))
	   (setq idx (mew-syntax-get-param ent "number"))
	   (if TTL
	       (if (and ttl (not (string= TTL ttl)))
		   (error "total mismatch"))
	     (setq TTL ttl))
	   (if FID
	       (if (or (null fid) (not (string= FID fid)))
		   (error "fragment id mismatch"))
	     (setq FID fid))
	   (unless idx (error "no number"))
	   (setq idx (1- (string-to-number idx)))
	   (if (and (>= idx 0) (< idx len))
	       (aset vec idx num)
	     (error "invalid number")))
	 (unless TTL (error "no total"))
	 (dotimes (i len)
	   (unless (stringp (aref vec i)) (error "Not enough fragments")))
	 ;; now reassemble
	 (mew-erase-buffer)
	 (mew-frwlet mew-cs-text-for-read mew-cs-text-for-write
	   ;; the first fragment
	   (goto-char (point-max))
	   (save-restriction
	     (narrow-to-region (point) (point))
	     (mew-insert-file-contents (mew-expand-msg cfld (aref vec 0)))
	     ;; Removing unnecessary fields from the encapsulating
	     ;; (outer) header.
	     (goto-char (point-min))
	     (mew-header-delete-lines mew-field-delete-for-joining)
	     ;; Concatenating the two headers.
	     (goto-char (point-min))
	     (re-search-forward mew-eoh nil t)
	     (setq beg (point))
	     (while (looking-at mew-eoh)
	       (forward-line)
	       (if (eobp) (error "invalid message (number 1)")))
	     (delete-region beg (point))
	     ;; Removing unnecessary fields from the encapsulated
	     ;; (inner) header.
	     (setq beg (point))
	     (when (re-search-forward mew-eoh nil t)
	       (setq regex (mew-make-field-regex mew-field-delete-for-joining))
	       (save-restriction
		 (narrow-to-region beg (point))
		 (goto-char (point-min))
		 (let ((case-fold-search t))
		   (while (not (eobp))
		     (if (looking-at regex)
			 (setq beg nil) ;; logic is reversed
		       (setq beg (point)))
		     (forward-line)
		     (mew-header-goto-next)
		     (if beg (delete-region beg (point))))))))
	   ;; the second and subsequent fragments.
	   (setq i 1)
	   (while (< i len)
	     (goto-char (point-max))
	     (save-restriction
	       (narrow-to-region (point) (point))
	       (mew-insert-file-contents (mew-expand-msg cfld (aref vec i)))
	       (goto-char (point-min))
	       (re-search-forward mew-eoh nil t)
	       (forward-line)
	       (if (eobp) (error "invalid message (number %d)" (1+ i)))
	       (delete-region (point-min) (point)))
	     (setq i (1+ i)))
	   (mew-header-delete-lines `(,mew-x-mew-uidl:))
	   (write-region (point-min) (point-max)
			 (mew-folder-new-message folder)
			 nil 'no-msg)))
       (mew-touch-folder folder)
       (message "Joining...done")
       (when mew-ask-folder-after-join
	 (if (y-or-n-p (format "Go to %s? " folder))
	     (mew-summary-visit-folder folder 'goend))))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Cleaning +trash
;;;

(defun mew-summary-clean-trash ()
  "Remove all messages in +trash."
  (interactive)
  (let* ((case (mew-sinfo-get-case))
	 (folder (mew-sinfo-get-folder))
	 case:trash trash trashdir msgs)
    (cond
     ((mew-folder-imapp folder)
      (setq trash (mew-imap-trash-folder case)))
     (t
      (setq trash mew-trash-folder)))
    (unless trash
      (setq trash folder))
    (setq case:trash (mew-input-folder case trash))
    (if (null case:trash)
	(message "Nothing was processed")
      (setq case (mew-case:folder-case case:trash))
      (setq trash (mew-case:folder-folder case:trash))
      (setq trashdir (mew-expand-folder case:trash))
      (setq msgs (mew-dir-messages trashdir))
      (if (and (mew-folder-localp trash) (null msgs))
	  (message "No messages to be removed in %s" trash)
	(if (not (y-or-n-p (format "Remove all messages in %s? " case:trash)))
	    (message "No messages removed in %s" trash)
	  (if (string= folder trash) (mew-summary-reset))
	  (message "Removing all messages in %s..." case:trash)
	  (when (get-buffer case:trash)
	    (with-current-buffer case:trash
	      (mew-summary-kill-subprocess)))
	  (mew-summary-unlink-msgs case:trash msgs)
	  (mew-summary-folder-cache-clean case:trash)
	  (message "Removing all messages in %s...done" case:trash)
	  (when (mew-folder-imapp trash)
	    (if (get-buffer case:trash)
		(set-buffer case:trash)
	      (mew-summary-switch-to-folder case:trash 'set-buffer))
	    (mew-imap-retrieve case 'exec case:trash
			       (mew-make-execinfo :remove '("1:*")
						  :rttl   0
						  :dttl   -1))))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Copy local
;;;

(defun mew-summary-local-copy ()
  "Copy a message to a local folder."
  (interactive)
  (mew-summary-msg-or-part
   (let ((fld (mew-summary-folder-name))
	 (exclusivep t)
	 msg dstmsg dstfld file dstfile)
     (save-excursion
       (mew-summary-goto-message)
       (setq msg (mew-summary-message-number)))
     (setq file (mew-expand-msg fld msg))
     (setq dstfld (mew-input-local-folder mew-inbox-folder))
     (when (and dstfld (mew-local-folder-check dstfld 'ask))
       (setq dstmsg (mew-folder-new-message dstfld 'numonly))
       (setq dstfile (mew-expand-msg dstfld dstmsg))
       (when (get-buffer dstfld)
	 (set-buffer dstfld)
	 (setq exclusivep (mew-summary-exclusive-p)))
       (cond
	((not exclusivep)
	 (message "Try again later"))
	((string= file dstfile)
	 (message "You cannot copy this onto itself"))
	(t
	 (mew-summary-local-copy-one file dstfile)
	 (mew-touch-folder dstfld)
	 (message "Copied to %s/%s" dstfld dstmsg)))))))

(defun mew-summary-mark-local-copy (&optional arg)
  "Copy messages marked with '*' to a local folder.  If called
with '\\[universal-argument]', only messages marked with '*' in
the region are handled."
 (interactive "P")
  (mew-summary-not-in-draft
   (let ((mew-use-highlight-x-face nil)
	 (fld (mew-summary-folder-name))
	 (exclusivep t)
	 msgs file dstmsg dstfld dstfile
	 beg end region total i)
     (if (mew-mark-active-p) (setq arg t))
     (cond
      (arg
       (setq region (mew-summary-get-region))
       (setq beg (car region))
       (setq end (cdr region)))
      (t
       (setq beg (point-min))
       (setq end (point-max))))
     (setq dstfld (mew-input-local-folder mew-inbox-folder))
     (when (and dstfld (mew-local-folder-check dstfld 'ask))
       (let ((mew-use-suffix nil))
	 (setq dstmsg (mew-folder-new-message dstfld 'numonly)))
       (setq msgs (mew-summary-mark-collect mew-mark-review beg end))
       (when (get-buffer dstfld)
	 (with-current-buffer dstfld
	   (setq exclusivep (mew-summary-exclusive-p))))
       (cond
	((null msgs)
	 (message "No mark"))
	((not exclusivep)
	 (message "Try again later"))
	(t
	 (message "Copying...")
	 (setq total (length msgs))
	 (setq i 1)
	 (dolist (msg msgs)
	   (setq file (mew-expand-msg fld msg))
	   (setq dstfile (mew-expand-new-msg dstfld dstmsg))
	   (message "Copying (%d/%d)..." i total)
	   (mew-summary-local-copy-one file dstfile)
	   (setq dstmsg (number-to-string (1+ (string-to-number dstmsg))))
	   (setq i (1+ i)))
	 (mew-touch-folder dstfld)
	 (message "Copying...done")))))))

(defun mew-summary-local-copy-one (srcfile dstfile)
  (with-temp-buffer
    (mew-frwlet mew-cs-text-for-read mew-cs-text-for-write
      (mew-insert-file-contents srcfile)
      (goto-char (point-min))
      (mew-header-delete-lines (list mew-x-mew-uidl:))
      (write-region (point-min) (point-max) dstfile nil 'no-msg)
      (mew-set-file-modes dstfile))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Deleting and moving a folder
;;;

(defun mew-summary-delete-folder ()
  "Delete this folder."
  (interactive)
  (mew-summary-only
   (let* ((folder (or (mew-sinfo-get-folder)
		      (mew-summary-folder-name 'ext)))
	  (case (mew-sinfo-get-case))
	  (case:folder (mew-summary-folder-name 'ext))
	  (dir (mew-expand-folder case:folder))
	  (buf (current-buffer)))
     (cond
      ((mew-folder-localp folder)
       (if (mew-folder-node-p folder)
	   (message "%s cannot be deleted" folder)
	 (when (y-or-n-p "Delete this folder? ")
	   (mew-delete-directory-recursively dir)
	   (mew-local-folder-delete folder)
	   (run-hook-with-args 'mew-summary-delete-folder-hook folder)
	   (mew-summary-visit-folder mew-inbox-folder)
	   (mew-kill-buffer buf))))
      ((mew-folder-imapp folder)
       (if (mew-folder-node-p folder case)
	   (message "%s cannot be deleted" folder)
	 (when (y-or-n-p "Delete this folder? ")
	   (setq mew-summary-buffer-process-error nil)
	   (mew-imap-retrieve case 'delete case:folder)
	   (mew-timing)
	   (mew-rendezvous mew-summary-buffer-process)
	   (if mew-summary-buffer-process-error
	       (progn
		 (message "%s cannot be deleted" folder)
		 (setq mew-summary-buffer-process-error nil))
	     (mew-imap-folder-delete case folder)
	     (mew-delete-directory-recursively dir) ;; cache
	     (run-hook-with-args 'mew-summary-delete-folder-hook case:folder)
	     (mew-summary-visit-folder mew-imap-inbox-folder)
	     (mew-kill-buffer buf)))))))))

(defun mew-summary-rename-folder ()
  "Rename this folder."
  (interactive)
  (mew-summary-only
   (let* ((folder (or (mew-sinfo-get-folder)
		      (mew-summary-folder-name 'ext)))
	  (case (mew-sinfo-get-case))
	  (case:folder (mew-summary-folder-name 'ext))
	  (dir (mew-expand-folder case:folder))
	  (buf (current-buffer))
	  new-folder new-dir case:new-folder)
     (cond
      ((mew-folder-localp folder)
       (setq new-folder (mew-input-local-folder folder))
       (setq new-dir (mew-expand-folder new-folder))
       (cond
	((string= folder new-folder)
	 (message "%s was not moved" folder))
	((file-exists-p new-dir)
	 (message "%s was not moved since %s exists" folder new-folder))
	(t
	 (mew-rename-directory dir new-dir)
	 (mew-summary-switch-to-folder new-folder)
	 (mew-kill-buffer buf)
	 (if (mew-folder-node-p folder)
	     ;; xxx remove all related buffer?
	     (mew-local-update 'force)
	   (mew-local-folder-delete folder)
	   (mew-local-folder-insert new-folder))
	 (run-hook-with-args 'mew-summary-rename-folder-hook folder new-folder))))
      ((mew-folder-imapp folder)
       (setq new-folder (car (mew-input-refile-folders (list folder) t case mew-folder-imap)))
       (setq case:new-folder (mew-case-folder case new-folder))
       (setq new-dir (mew-expand-folder case:new-folder))
       (cond
	((string= folder new-folder)
	 (message "%s was not moved" folder))
	((file-exists-p new-dir)
	 (message "%s was not moved since %s exists" folder new-folder))
	(t
	 (mew-imap-retrieve case 'rename case:folder case:new-folder)
	 (mew-timing)
	 (mew-rendezvous mew-summary-buffer-process)
	 (if mew-summary-buffer-process-error
	     (progn
	       (message "%s cannot be renamed" folder)
	       (setq mew-summary-buffer-process-error nil))
	   (rename-file dir new-dir t) ;; cache
	   (mew-summary-switch-to-folder case:new-folder)
	   (mew-kill-buffer buf)
	   (if (mew-folder-node-p folder case)
	       (if (y-or-n-p "Collect folders now? ")
		   (mew-imap-update case)
		 (mew-message-for-summary "Type '\\[universal-argument]\\[mew-status-update]' to collect folders"))
	     (mew-imap-folder-delete case folder)
	     (mew-imap-folder-insert case new-folder))
	   (run-hook-with-args 'mew-summary-rename-folder-hook
			       case:folder case:new-folder)))))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Toggle
;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Summary only vs Summary/Message
;;;

(defun mew-summary-toggle-disp-msg (&optional arg)
  "Toggle 'Summary mode only' and 'Summary & Message mode'. If
you choose 'Summary mode only', you can quickly put the delete
	marks since the next message is not displayed."
  (interactive)
  (cond
   ((eq arg 'on)
    (mew-sinfo-set-disp-msg t))
   ((eq arg 'off)
    (mew-sinfo-set-disp-msg nil)
    (mew-summary-reset-mode-line))
   (t
    (mew-sinfo-set-disp-msg (not (mew-sinfo-get-disp-msg)))
    (if (mew-sinfo-get-disp-msg)
	(mew-summary-display 'redisplay)
      (mew-summary-goto-message)
      (mew-summary-reset)
      (mew-summary-cook-window))))
  (run-hooks 'mew-summary-toggle-disp-msg-hook))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 8bit clean
;;;

(defun mew-summary-toggle-8bit ()
  "Toggle 8bit mode(i.e. 'mew-use-8bit')."
  (interactive)
  (setq mew-use-8bit (not mew-use-8bit))
  (if mew-use-8bit
      (message "mew-use-8bit has been set to 't'")
    (message "mew-use-8bit has been set to 'nil'")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Mew cache clean up
;;;

(defun mew-summary-cache-clean-up ()
  "Clean-up caches of analyzed messages."
  (interactive)
  (mew-cache-clean-up)
  (message "Mew cache clean up...done"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Toggle warning
;;;

(defun mew-summary-toggle-warning ()
  "Toggle warning level.
If 'mew-warning-field-level' is 2, set it to 1.
If 'mew-warning-field-level' is 1, set it to 2."
  (interactive)
  (if (= mew-warning-field-level 2)
      (setq mew-warning-field-level 1)
    (setq mew-warning-field-level 2))
  (mew-cache-clean-up)
  (mew-summary-analyze-again)
  (message "Mew warning level %d" mew-warning-field-level))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Toggle decode policy
;;;

(defun mew-summary-toggle-policy (&optional arg)
  "Toggle decode policy(i.e. 'mew-decode-broken')."
  (interactive "P")
  (if arg
      (setq mew-decode-broken nil
	    mew-use-name-parameter nil)
    (setq mew-decode-broken (not mew-decode-broken))
    (setq mew-use-name-parameter (not mew-use-name-parameter)))
  (mew-cache-clean-up)
  (mew-summary-analyze-again)
  (message "Mew \"%s\" mode" (if mew-decode-broken "TOLERANT" "STRICT")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Toggle debug
;;;

(defun mew-summary-toggle-debug ()
  "Toggle 'mew-debug'."
  (interactive)
  (setq mew-debug (not mew-debug))
  (if mew-debug
      (message "'mew-debug' is now 't'")
    (message "'mew-debug' is now 'nil'")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Toggle PGP/MIME and old PGP
;;;

(defun mew-summary-toggle-pgp ()
  "Toggle PGP/MIME and old PGP (i.e. 'mew-use-old-pgp')."
  (interactive)
  (setq mew-use-old-pgp (not mew-use-old-pgp))
  (if mew-use-old-pgp
      (message "mew-use-old-pgp has been set to 't'")
    (message "mew-use-old-pgp has been set to 'nil'")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Learning spam and ham
;;;

(defun mew-summary-learn-spam ()
  "Learn that this message is a spam.
See also 'mew-spam-prog' and 'mew-spam-prog-args."
  (interactive)
  (mew-summary-msg
   (let* ((fld (mew-summary-folder-name))
	  (msg (mew-summary-message-number))
	  (file (mew-expand-msg fld msg))
	  (case (mew-sinfo-get-case))
	  (prog (mew-spam-prog case))
	  (args (mew-spam-prog-args case))
	  beg end)
     (message "Learning as spam...")
     (when (mew-which-exec prog)
       (with-temp-buffer
	 (apply 'call-process prog file (current-buffer) nil args)
	 (setq beg (point-min))
	 (goto-char beg)
	 (forward-line)
	 (if (= (point) beg)
	     (message "Learning as spam...done")
	   (setq end (1- (point)))
	   (message "%s" (concat "Learned as spam: " (mew-buffer-substring beg end)))))))))

(defun mew-summary-learn-ham ()
  "Learn that this message is a ham.
See also 'mew-ham-prog' and 'mew-ham-prog-args."
  (interactive)
  (mew-summary-msg
   (let* ((fld (mew-summary-folder-name))
	  (msg (mew-summary-message-number))
	  (file (mew-expand-msg fld msg))
	  (case (mew-sinfo-get-case))
	  (prog (mew-ham-prog case))
	  (args (mew-ham-prog-args case))
	  beg end)
     (message "Learning as ham...")
     (when (mew-which-exec prog)
       (with-temp-buffer
	 (apply 'call-process prog file (current-buffer) nil args)
	 (setq beg (point-min))
	 (goto-char beg)
	 (forward-line)
	 (if (= (point) beg)
	     (message "Learning as ham...done")
	   (setq end (1- (point)))
	   (message "%s" (concat "Learned as ham: " (mew-buffer-substring beg end)))))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Search invisible
;;;

(defun mew-summary-toggle-invisible ()
  "Toggle the value of search-invisible.
Invisible information in Summary mode cannot be searched by default.
Executing this command enables searching such information."
  (interactive)
  (if (eq search-invisible t)
      (setq search-invisible 'open)
    (setq search-invisible t))
  (message "'search-invisible' is set to '%s'" search-invisible))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Lines
;;;

(defun mew-summary-line ()
  "Toggle normal lines, wrapped lines and long lines."
  (interactive)
  (let ((fld (mew-summary-folder-name))
	(msg (mew-summary-message-number))
	(cwin (get-buffer-window (current-buffer)))
	(mwin (get-buffer-window (mew-buffer-message))))
    (if (not mwin)
	(message "No message is displayed")
      (select-window mwin)
      (unwind-protect
	  (progn
	    (mew-message-line)
	    (mew-message-mode-line fld msg))
	(select-window cwin)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Horizontal Scrolling
;;;

(defun mew-summary-scroll-left ()
  "Scroll the Message window to the right."
  (interactive)
  (let ((cwin (get-buffer-window (current-buffer)))
	(mwin (get-buffer-window (mew-buffer-message))))
    (if (not mwin)
	(message "No message is displayed")
      (select-window mwin)
      (unwind-protect
	  (mew-message-scroll-left)
	(select-window cwin)))))

(defun mew-summary-scroll-right ()
  "Scroll the Message window to the left."
  (interactive)
  (let ((cwin (get-buffer-window (current-buffer)))
	(mwin (get-buffer-window (mew-buffer-message))))
    (if (not mwin)
	(message "No message is displayed")
      (select-window mwin)
      (unwind-protect
	  (mew-message-scroll-right)
	(select-window cwin)))))

(provide 'mew-summary4)

;;; Copyright Notice:

;; Copyright (C) 1996-2015 Mew developing team.
;; All rights reserved.

;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;;
;; 1. Redistributions of source code must retain the above copyright
;;    notice, this list of conditions and the following disclaimer.
;; 2. Redistributions in binary form must reproduce the above copyright
;;    notice, this list of conditions and the following disclaimer in the
;;    documentation and/or other materials provided with the distribution.
;; 3. Neither the name of the team nor the names of its contributors
;;    may be used to endorse or promote products derived from this software
;;    without specific prior written permission.
;;
;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
;; PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

;;; mew-summary4.el ends here