# NOTE: THIS IS NO LONGER NEEDED SINCE ELM ALIASES ARE
#       DIRECTLY SUPPORTED BY TKMAIL NOW . I leave it
#       hear as a code example.

# Contributed by Todd Chamberlain <todd@atlas.cb.att.com>
# adapted from code by Jay Sekora <js@princeton.edu>

# Place the following procedure in your ~/.tkmail file in
# order to get a menu of your elm aliases in the compose
# window. You may need to change the location of the aliases
# file.
proc mf_compose_hook { mfc } {
  global mf mfp env

  set filename "$env(HOME)/.elm/aliases.text"

  if {![file exists $filename]} then {
    return -1
  } else {
    # Define alias menu
    menubutton $mfc.menu.alias -text {Alias} -menu $mfc.menu.alias.m
    menu $mfc.menu.alias.m
    # Open aliases.text file
    set file [open $filename {r}]
    foreach line [split [read $file] "\n"] {
      if [regexp {^#} $line] then {break}
      if [regexp {^[    ]*$} $line] then {break}
      # strip space around equals signs:
      regsub -all { *= *} $line {=} line
      set topfields [split $line {=}]
      # Add entry into alias menu
      # Position 0 -- alias
      # Position 1 -- full name
      # Position 2 -- email address
      $mfc.menu.alias.m add command -label [lindex $topfields 1] \
           -command "$mfc.to.ent delete 0 end;\
                $mfc.to.ent insert 0 \{[lindex $topfields 2]\}"
    }
  pack append $mfc.menu $mfc.menu.alias {left}
  }
}

