# Code Organization
by Brent Welch

I've tried to split exmh into meaningful modules, separating display modules (fdisp, for instance) from those that maintain display-independent data structures (like flist). Features like the `Find` and `Pick` dialogs are in their own file, so you can easily replace those. I have not documented the interfaces between modules at all, so you'll have to read some code. It's easy to find definitions: the .tcl file names reflect the names of the procedures that they define. In addition, many modules use a global array to hold their state variables; this array variable has the same name as the module.

If you are really interested in the internals of exmh (that is, if something about it really bugs you!), you can look into the implementation to see what is wrong and how you might do things better. The following sections contain a list of the files that make up exmh and short explanations of the Tcl procedures in each.

## Main Scripts

The sources are divided into two parts. The main scripts include exmh and some associated utility scripts. The files with the .MASTER suffix are patched with site-dependent information before they are installed. The remaining sources are kept in a script library. The library files are loaded on demand by the Tcl auto_load facility.

exmh.MASTER
  This is the main script. It gets patched with site-dependent information, and the results are written to exmh, which gets installed. exmh.MASTER doesn't define much because it loads almost everything from the script library.
exmh-bg.MASTER
  This is the main script for the background process. It redefines a few procedures and loads the rest of its implementation from the library. The initial rendezvous between the background process is implemented in this script and in some supporting routines in background.tcl.
install.tcl
  These are supporting routines for the installation process. This should be generic enough for use with your own Tcl application. Feel free to borrow it.
exmh.install
  This is the installation script for exmh.
exmh-async
  This is the wrapper for external editors.

## Library

The remainder of the files are kept in the script library.

aliases.tcl
  A browser for the MH alias file.
background.tcl
  The background processing module. This can run in a separate process or as part of the main process. The `BgRPC` routine is used to invoke a background operation, and it works in either case.
bindings.tcl
  The default bindings and the implementation of the binding user interface.
busy.tcl
  Three different ways to indicate that exmh is busy doing something.
buttons.tcl
  The resource-based button and menu implementation.
cutbuffer.tcl
  A stub for the C cutbuffer extension. If you have added the extension to your wish, you'll have slightly better cut-and-paste interoperability with older X programs.
editor.tcl
  The interface to editors for message composition.
error.tcl
  The error handler.
extrasInit.tcl
  This has Init routines for optional modules. The idea is to avoid loading the modules until they are actually used.
exwin.tcl
  The main window display is set up here. The code that remembers where top-level windows go is here.
faces.tcl
  The interface to the faces database.
fcache.tcl
  The folder cache display.
fdisp.tcl
  The main folder display.
fdispColor.tcl
  The color definitions for the folder display.
fdispPopup.tcl
  The nested folder popup implementation.
fileselect.tcl
  The file selection dialog.
find.tcl
  The find dialog.
flag.tcl
  Manages the appearance of the icon.
flist.tcl
  Manages the set of unseen folders.
folder.tcl
  Folder operations like `Folder_Change` and `Folder_Commit`.
folderNew.tcl
  The folder-create and -delete dialogs.
ftoc.tcl
  The folder table of contents (scan listing).
ftocColor.tcl
  Color definitions for the highlights in the table of contents.
ftocFind.tcl
  Routines that search over the table of contents.
help.tcl
  Some very simple help text and a color key.
import.tcl
  Routines to import folders from UCB mail.
inc.tcl
  Several ways to incorporate mail.
labels.tcl
  There are three labels in the display -- can you see them?
mailcap.tcl
  Routines to parse the MIME mailcap files.
main.tcl
  The main `Exmh` procedure, plus `Exmh_Status` and `Exmh_Debug`.
mh.tcl
  A basic layer on top of the MH commands.
mime.tcl
  The MIME display code.
msg.tcl
  Message operations -- although these tend to be distributed partly among ftoc.tcl and mh.tcl as well.
msgShow.tcl
  This used to be the main message display code, but it has become dwarfed by the MIME display.
pgp.tcl
  An interface to the Pretty Good Privacy system.
pick.tcl
  An interface to the MH pick program.
preferences.tcl
  The Preferences user interface.
print.tcl
  Routines to print messages.
rich2tk.tcl
  This parses text/enriched MIME contents.
scan.tcl
  This manages the scan caches.
sedit.tcl
  The main routines for the built-in editor.
seditBind.tcl
  The keybindings for the built-in editor.
seditCompose.tcl
  The table of compose key sequences that insert 8-bit characters is defined here.
seditEnriched.tcl
  Implements the composition of text/enriched.
seditExtras.tcl
  More editor stuff, like `Whom`, `Spell`, `Sign`, `Find`, and the dialogs associated with `Insert Part`.
seditMime.tcl
  Implements the MIME multipart structuring.
seditQP.tcl
  Support for quoted-printable encoding of outgoing messages.
select.tcl
  Implements the keyboard selection of folders and messages.
sound.tcl
  Sound effects.
text.tcl
  Some text tagging routines.
textButton.tcl
  An implementation of a pseudo-button in a text widget. This used to be part of the MIME display code but is no longer used.
textSelect.tcl
  The main guts of text bindings.
user.tcl
  Stubs for `User_Init` and `User_Layout`.
widgetMenu.tcl
  Support for the popup menus used in MIME messages.
widgetText.tcl
  Handles constrained text scrolling and dragging a selection off the window.
widgets.tcl
  A basic layer on top of the Tk widgets. These routines integrate the pack geometry manager. Even more important, they guard against errors that occur because of missing fonts. You should try to use these instead of the straight Tk widget commands.
xns.tcl
  An interface to xnsgetmail for those folks with mail on an XNS mail server.