To: ifile-discuss@cs.cmu.edu
Subject: full exmh integration!
From: Jason Daniel Rennie <jr6b+@andrew.cmu.edu>
Date: Fri, 18 Jul 1997 23:46:55 -0400

After figuring out how to add a button for filtering mail through ifile, I
figured it would be fun to see if I could more fully integrate ifilter    
into EXMH in the same fashion that slocal is integrated.  Well, 
my attempts have been successfull. :)  If you would like to have ifile 
better integrated into EXMH, I have listed below a description of what 
I had to do to get it working.  Hopefully, it will work for others too.
                    
The first thing you will need to do is to add a line like the following to
the top section of your exmh script:                                     

set exmh(ifilter) /afs/cs/usr/jr6b/usr/Linux/bin/ifilter

This will tell EXMH where to find your ifilter binary. Of course, 
you'll need to change the path to the location of your ifilter
binary.

Next, you'll need to copy the inc.tcl file which came with your EXMH 
distribution to your ~/.tk/exmh/ directory.  Once you have done that, 
you will want to open ~/.tk/exmh/inc.tcl and change it according to the 
following diff.  Note that the first few lines will allow you to chose 
an 'ifile' option for Preferences->Incorporate Mail->Ways to Inc.  The 
later lines simply define the ifile incorporation procedure.  If you've 
hacked the inc.tcl code before, you will notice an uncanny resemblence 
of the Inc_iFile function to the Inc_Presort function :)

----diff -c2 ~/.tk/exmh/inc.tcl /usr/local/lib/exmh-2.0gamma/lib/inc.tcl---- 
*** /usr/local/lib/exmh-2.0gamma/lib/inc.tcl	Fri Sep 27 20:11:47 1996
--- ~/.tk/tcl/inc.tcl	Fri Jul 18 23:25:47 1997
***************
*** 30,34 ****
      Preferences_Add "Incorporate Mail" \
  "Exmh knows several ways to incorporate mail from your system's spool file into the MH folder hierarchy." {
! 	{inc(style) incStyle	{CHOICE inbox presort multidrop presortmulti none} {Ways to Inc}
  "inbox - basic MH inc from your spool file to inbox folder.
  presort - slocal filtering directly into various folders.
--- 30,34 ----
      Preferences_Add "Incorporate Mail" \
  "Exmh knows several ways to incorporate mail from your system's spool file into the MH folder hierarchy." {
! 	{inc(style) incStyle	{CHOICE inbox presort multidrop presortmulti ifile none} {Ways to Inc}
  "inbox - basic MH inc from your spool file to inbox folder.
  presort - slocal filtering directly into various folders.
***************
*** 36,39 ****
--- 36,41 ----
  as specified by ~/.xmhcheck, that are in turn inc'ed into folders.
  presortmulti - presort + multidrop.
+ ifile - intelligent message content filtering directly into various folders.
+ Please read ifile.README for more detailed information.
  none - you have an external agent that handles inc for you, so
  don't bother trying it from within exmh."}
***************
*** 90,94 ****
  }
  proc IncInner {} {
!     # There are three different styles of inc'ing messages...
      global inc
      if $inc(xnsgetmail) {
--- 92,96 ----
  }
  proc IncInner {} {
!     # There are four different styles of inc'ing messages...
      global inc
      if $inc(xnsgetmail) {
***************
*** 100,103 ****
--- 102,106 ----
  	multidrop	{ busy Inc_All }
  	presortmulti	{ busy Inc_PresortMultidrop }
+ 	ifile		{ busy Inc_iFile }
  	none		{ return }
      }
***************
*** 287,290 ****
--- 290,371 ----
      }
  }
+ proc Inc_iFile {} {
+     # Transfer from the mail spool file directly into folders
+     global exmh mhProfile env inc
+     # Use inc to copy stuff into a temp directory
+     if ![file isdirectory $mhProfile(path)/MyIncTmp] {
+ 	exec mkdir $mhProfile(path)/MyIncTmp
+     }
+     if {[catch {exec inc +MyIncTmp -silent} err]} {
+ 	# Some versions of inc exit non-zero when they should not.
+ 	Exmh_Debug Inc_Presort +MyIncTmp: $err
+     }
+     if [catch {set env(USER)} user] {
+ 	if [catch {set env(LOGNAME)} user] {
+ 	    Exmh_Status "No USER or LOGNAME envar"
+ 	    set user ""
+ 	}
+     }
+     if {[catch {glob $mhProfile(path)/MyIncTmp/*} files] == 0} {
+ 	Exmh_Status "ifile inc ..."
+ 	foreach file $files {
+ 	    if {[string compare [file tail $file] "++"] == 0} {
+ 		if [catch {exec rm $file} err] {
+ 		    Exmh_Debug Inc_iFile: $err
+ 		}
+ 		continue
+ 	    }
+ 	    if {$inc(presortFeedback)} {
+ 		if [catch {exec grep "^Subject:" $file | head -1} \
+ 		    subject] {
+ 		    set subject ""
+ 		}
+ 	    }
+ 		
+ 	    # now use ifilter to (presumably) shift things to a folder
+ 	    if [catch {exec $exmh(ifilter) < $file} err] {
+ 		# Move it out of MyIncTmp in case it really did
+ 		# get filed somewhere.  Certain file system errors
+ 		# (can't stat .) lead to this behavior
+ 		Exmh_Status "$file - $err - check MyIncErrors"
+ 		if ![file isdirectory $mhProfile(path)/MyIncErrors] {
+ 		    exec mkdir $mhProfile(path)/MyIncErrors
+ 		}
+ 		Mh_Refile MyIncTmp [file tail $file] MyIncErrors 
+ 	    } else {
+ 		if [catch {exec rm $file} err] {
+ 		    Exmh_Debug Inc_iFile: $err
+ 		}
+ 		if {$inc(presortFeedback)} {
+ 		    if {[string length $subject] > 0} {
+ 			regsub "^Subject: *" $subject "" subject
+ 			Exmh_Status "[file tail $file]: $subject" red
+ 		    } else {
+ 			Exmh_Status [file tail $file] red
+ 		    }
+ 		}
+ 	    }
+ 	}
+     }
+     catch {exec rm -f $mhProfile(path)/MyIncTmp/$mhProfile(mh-sequences)}
+     catch {exec rmdir $mhProfile(path)/MyIncTmp}
+ 
+     Flist_FindUnseen		;# Needed to set new message state.
+     # This after breaks a potential deadlock:
+     # UI Inc button is pressed - registers outstanding Inc operation
+     # PresortFinish notes new messages in the current folder and wants
+     # to rescan the folder to pick up the changes.
+     # The scan notes the outstanding operation and waits for it to complete.
+     # Deadlock
+     after 1 {BgRPC Inc_iFileFinish}
+ }
+ proc Inc_iFileFinish {} {
+     global exmh ftoc
+     Mh_Folder $exmh(folder)	;# Inc_iFile inc has changed this to MyIncTmp
+     if {$ftoc(displayValid) && [Flist_NumUnseen $exmh(folder)] > 0} {
+ 	Label_Folder $exmh(folder)
+ 	Scan_Folder $exmh(folder) $ftoc(showNew)
+      }
+  }
  
  # The following are useful if you have lots of drop boxes
----diff -c2 ~/.tk/exmh/inc.tcl /usr/local/lib/exmh-2.0gamma/lib/inc.tcl----

Jason Rennie                                       jr6b+@andrew.cmu.edu
    School of Computer Science - Carnegie Mellon University
  Text Learning - Table Tennis - Fencing - Linux - ifile - Prog Rock
