home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Mail / appnmail-1.8-Solaris / mailapp-utilities / MyMail.ts < prev    next >
Encoding:
Text File  |  1996-11-24  |  8.9 KB  |  304 lines

  1. # Begin TickleServices Version 1.02mab Data
  2. "Divider" = "196.000000";
  3. "Menu Item" = "!Initialization!";
  4. "Tcl" = "\
  5.     # This version of exec doesn't strip the trailing newline from th\
  6. e
  7.     # output.
  8. proc nexec {args} {
  9.     set fileId [uplevel open [list [format \"|%s\" $args]]]
  10.     set ret [read $fileId]
  11.     close $fileId
  12.     return $ret
  13. }
  14.  
  15.     # Reads the specified file and returns the text.
  16. proc readfile {filename {hexcode 0}} {
  17.     set fileId [open $filename r]
  18.     if {$hexcode} {
  19.         set ret [read -hexcode $fileId]
  20.     } else {
  21.         set ret [read $fileId]
  22.     }
  23.     close $fileId
  24.     return $ret
  25. }
  26.  
  27.     # Writes the text to the specified file.
  28. proc writefile {filename text {hexcode 0}} {
  29.     set fileId [open $filename w]
  30.     if {$hexcode} {
  31.         set ret [puts -nonewline -hexcode $fileId $text]
  32.     } else {
  33.         set ret [puts -nonewline $fileId $text]
  34.     }
  35.     close $fileId
  36.     return $ret
  37. }
  38.  
  39.     # read the quoteString from the defaults database.  The quoteStri\
  40. ng
  41.     # defaults to \">\", which is a semi-standard quoting character.
  42. global quoteString
  43. set quoteString [defaults read TickleServices QuoteString \">\"]
  44.  
  45.     # Ditto for the maximum length of text lines
  46. global lineLength
  47. set lineLength [defaults read Mail LineLength 72]
  48.  
  49. proc prepend {str prefix} {
  50.     set str [string trimright \"\\n$str\" \"\\n\"]    
  51.     regsub -all \"\\n\" $str \"\\n[escape $prefix {\\\\&\\[\\]}]\" st\
  52. r
  53.     return \"[string range $str 1 end]\\n\"
  54. }
  55.  
  56. proc unprepend {str prefix} {
  57.     set str \"\\n$str\"
  58.     regsub -all \"\\n[escape $prefix {\\\\&\\[\\]}]\" $str \"\\n\" st\
  59. r
  60.     return [string range $str 1 end]
  61. }
  62.  
  63. proc refmt {str ll} {
  64.    set out \"\"
  65.    set pos 0
  66.    set prefix \"\"
  67.    regsub -all \"\\t\" $str \"        \" str
  68.    foreach line [split [string trim $str \"\\n\"] \"\\n\"] {
  69.       regexp \"^(\\[ >\\]*)(.*)$\" $line line nprefix text
  70.       if {$prefix!=$nprefix} {
  71.      if {$pos!=0} {append out \"\\n\"}
  72.          set prefix $nprefix
  73.      set pos 0
  74.      }
  75.       if {$text==\"\"} {
  76.          if {$pos!=0} {append out \"\\n\"}
  77.          append out \"$prefix\\n\"
  78.      set pos 0
  79.      continue
  80.       }
  81.       foreach word [split $text \" \"] {
  82.         if {$pos==0 || $pos+1+[string length $word] >= $ll} {
  83.        if {$word==\"\"} continue
  84.        if {$pos>0} {append out \"\\n\"}
  85.        append out $prefix
  86.        set pos [string length $prefix]
  87.        append out $word
  88.        incr pos [string length $word]
  89.     } else {
  90.        append out \" \"
  91.        incr pos
  92.        append out $word
  93.        incr pos [string length $word]
  94.     } } }
  95.    if {$pos!=0} { append out \"\\n\" }
  96.    return $out
  97. }
  98.  
  99.     # This is a dis-gusting procedure to convert a Text-style RTF
  100.     # string with attachments into a Mail2.1-style RTF string with
  101.     # attachments.  The basic problem this routine solves is that
  102.     # where Edit stores attachments as
  103.     #     {...{\\NeXTGraphic# attachmentName \\width# \\height#\\n}..\
  104. .},
  105.     # Mail stores them as {{\\attachment# attachmentName\\n}\\n}.
  106.     # The attachmentName and the first # (which gives the position
  107.     # of the attachment in the text) must be extracted and placed
  108.     # in their new home.  Furthermore, the attachmentName must be
  109.     # expanded to and absolute pathname.
  110. proc convertRTF2x {textStyle filename} {
  111.     set addin 0
  112.     while {[regexp \"{\\[^{\\]*{\\\\\\\\NeXTGraphic(\\[0-9\\]*) (\\[^\
  113. \\n\\]*) \\\\\\\\width\\[0-9\\]* \\\\\\\\height\\[0-9\\]*\\n}\\[^}\\]\
  114. *}\" $textStyle directive position attachment]} {
  115.     set esc [escape $directive \"|*+?.^\\$\\\\\\[\\]\"]
  116.     
  117.         # Add in an adjustment because Edit counts the graphic
  118.         # as a character, whereas Mail does not, so the Edit
  119.         # position must be adjusted downward for each graphic.
  120.     incr position $addin
  121.     incr addin -1
  122.     set rep [escape \"{{\\\\attachment$position $filename/$attachment\\n\
  123. }\\n}\" \"\\\\&\"]
  124.     if {![regsub -all $esc $textStyle $rep textStyle]} {
  125.         # It _must_ have replaced a directive, since we
  126.         # found one.  This is an attempt to prevent infinite
  127.         # loops caused by never replacing what we found in
  128.         # regexp.
  129.         error \"Unable to process RTF directive\"
  130.     }
  131.     }
  132.     return $textStyle
  133. }
  134.  
  135. proc convertRTF30 {textStyle filename} {
  136.     regsub -all \"({\\\\\\\\NeXTGraphic\\[0-9\\]* *)(\\[^\\n\\]* \\\\\
  137. \\\\width\\[0-9\\]* \\\\\\\\height\\[0-9\\]*\\n})\" $textStyle \"\\\\\
  138. 1$filename/\\\\2\" textStyle
  139.     return $textStyle
  140. }
  141.  
  142. proc convertRTF {textStyle filename} {
  143.     return $textStyle
  144. }";
  145. "Window Size" = "{ 728.000, 364.000}";
  146. |
  147. "Menu Item" = "MyMail/Deliver";
  148. "Send Type" = "NXAsciiPboardType";
  149. "Tcl" = "\
  150. # Call sendmail to write the passed data to the user's mailbox.
  151.  
  152. if {![info exists whoami]} {
  153.     set whoami [exec /usr/ucb/whoami]
  154. }
  155. exec /usr/lib/sendmail $whoami << [pasteboard read]
  156. ";
  157. |
  158. "Key Equivalent" = "F";
  159. "Menu Item" = "MyMail/Format Text";
  160. "Receive Type" = "NXAsciiPboardType";
  161. "Send Type" = "NXAsciiPboardType";
  162. "Tcl" = "\
  163. # Reformat the selection to less than $lineLength columns.
  164.  
  165. pasteboard write [refmt [pasteboard read] $lineLength]
  166. ";
  167. |
  168. "Key Equivalent" = "I";
  169. "Menu Item" = "MyMail/Insert Signature";
  170. "Receive Type" = "NXAsciiPboardType";
  171. "Receive Type" = "NXRTFPboardType";
  172. "Tcl" = "\
  173. # Return text of ASCII and/or RTF signature file.
  174.  
  175. # Get the signature file default 
  176. set asciiSigFile [defaults read TickleServices SignatureFile ~/.signa\
  177. ture]
  178. if {[file exists $asciiSigFile]} {
  179.    set asciiSig \"---\\n[readfile [glob $asciiSigFile]]\"
  180. } else { set asciiSig \"\" }
  181.  
  182. set rtfSigFile [defaults read TickleServices RTFSignatureFile ~/.sign\
  183. ature.rtf]
  184. if {[file exists $rtfSigFile]} {
  185.   if {[file isdirectory $rtfSigFile]} {
  186.     set rtfSig [convertRTF [readfile $rtfSigFile/TXT.rtf] $rtfSigFile\
  187. ]
  188.     puts stdout $rtfSig
  189.   } else { set rtfSig [readfile [glob $rtfSigFile]] }
  190. } else { set rtfSig \"\" }
  191.  
  192. if {$rtfSig!=\"\" && $asciiSig!=\"\"} {
  193.   pasteboard declare $NXRTFPboardType $NXAsciiPboardType
  194.   pasteboard write $rtfSig $NXRTFPboardType
  195.   pasteboard write $asciiSig $NXAsciiPboardType
  196. } elseif {$rtfSig!=\"\"} {
  197.   pasteboard write $rtfSig $NXRTFPboardType
  198. } elseif {$asciiSig!=\"\"} {
  199.   pasteboard write $asciiSig $NXAsciiPboardType
  200. } else {
  201.   alertpanel {Insert Signature} \"Unable to find `$asciiSigFile' or `\
  202. $rtfSigFile'.\"
  203. }
  204. ";
  205. |
  206. "Key Equivalent" = ">";
  207. "Menu Item" = "MyMail/Quote Text";
  208. "Receive Type" = "NXAsciiPboardType";
  209. "Send Type" = "NXAsciiPboardType";
  210. "Tcl" = "\
  211. # Quote the selection with the default quoteString.  See !Initializat\
  212. ion!
  213. # for info on quoteString.
  214.  
  215. pasteboard write [refmt [prepend [pasteboard read] $quoteString] $lin\
  216. eLength]
  217.  
  218. ";
  219. |
  220. "Key Equivalent" = "R";
  221. "Menu Item" = "MyMail/Reply Text";
  222. "Send Type" = "NeXTmail Message pasteboard type";
  223. "Tcl" = "\
  224. set mail [exec /usr/bin/rtf-ascii << [pasteboard read $NXRTFPboardTyp\
  225. e]]
  226. set pos [string first \"\\n\\n\" $mail]
  227. set header \"\\n[string range $mail 0 [expr {$pos}]]\"
  228. regexp \"\\nFrom: (\\[^\\n\\]*)\\n\" $header null from
  229. regexp \"\\nSubject: (\\[^\\n\\]*)\\n\" $header null subject
  230.  
  231. if {[regexp \"^R\\[Ee\\]: \" $subject]==0} { set subject \"Re: $subje\
  232. ct\" }
  233.  
  234. exec /usr/local/bin/nextmail -e -s \"$subject\" $from << [refmt [prep\
  235. end [string range $mail [expr {$pos+2}] end] $quoteString] $lineLengt\
  236. h]
  237. ";
  238. |
  239. "Menu Item" = "MyMail/Set Quote String";
  240. "Send Type" = "NXAsciiPboardType";
  241. "Tcl" = "\
  242. # Set the default quoteString.
  243.  
  244.     # In general quote strings shouldn't contain newlines.
  245. if {[string first \"\\n\" [pasteboard read]]!=-1} {
  246.     if {[alertpanel \"Set Quote String\" \"Selected quote string cont\
  247. ains one or more newlines.  Are you certain you wish to use this quot\
  248. e string?\" \"Cancel\" \"OK\"]==1} {
  249.         return
  250.     }
  251. }
  252.  
  253.     # Set the current value, and also the default for future use.
  254. set quoteString [pasteboard read]
  255. defaults write TickleServices QuoteString $quoteString
  256. ";
  257. |
  258. "Menu Item" = "MyMail/Set Signature";
  259. "Send Type" = "NXAsciiPboardType";
  260. "Send Type" = "NXRTFPboardType";
  261. "Tcl" = "\
  262. # Set the signature.
  263.  
  264. if {[lindex [pasteboard types] 0]==$NXRTFPboardType} {
  265.    set sigFile [defaults read TickleServices RTFSignatureFile ~/.sign\
  266. ature.rtf] 
  267.    set sigType $NXRTFPboardType
  268.    } else {
  269.    set sigFile [defaults read TickleServices SignatureFile ~/.signatu\
  270. re]
  271.    set sigType $NXAsciiPboardType
  272.    }
  273.  
  274.     # Get the signature file default and glob it to make it absolute.
  275. set globFile [glob $sigFile]
  276.  
  277.     # Give the user a last change before overwriting the file.
  278. if {[file exists $globFile]} {
  279.     if {[alertpanel {Set Signature} \"Overwrite current signature in \
  280. $sigFile?\" {OK} {Cancel}]!=1} {
  281.     return
  282.     }
  283.     # Still, what if they might want it back?  Back it up.
  284.     catch {exec mv $globFile $globFile~}
  285. }
  286.  
  287.     # Write the signature file from the pasteboard.
  288. writefile $globFile [pasteboard read $sigType]
  289. ";
  290. |
  291. "Key Equivalent" = "<";
  292. "Menu Item" = "MyMail/Unquote Text";
  293. "Receive Type" = "NXAsciiPboardType";
  294. "Send Type" = "NXAsciiPboardType";
  295. "Tcl" = "\
  296. # Unquote the selection with the default quoteString.  See !Initializ\
  297. ation!
  298. # for info on quoteString.
  299.  
  300. pasteboard write [refmt [unprepend [pasteboard read] $quoteString] $l\
  301. ineLength]
  302. ";
  303. # End TickleServices Data
  304.