home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 March / Chip_2002-03_cd1.bin / tema / pegasus / download / w32-401.exe / TEMPLATE.TXT < prev    next >
Text File  |  1999-11-22  |  21KB  |  498 lines

  1. ----------------------------------------------------------------------
  2.                      Pegasus Mail Message Templates
  3. ----------------------------------------------------------------------
  4.                           Pegasus Mail System, 
  5.        Copyright (c) 1990-99, David Harris, All Rights Reserved.
  6. ----------------------------------------------------------------------
  7.  
  8.  
  9. Contents:
  10.  
  11. 1:              Overview of Message Templates
  12. 2:              Types of Templates
  13. 3:              Using Templates within Pegasus Mail
  14. 4:              The Message Template Script Language
  15.   4.1:          String literals
  16.       4.1.1:    Filenames
  17.   4.2:          Optional parameters
  18.   4.3:          Command substitutions
  19.   4.4:          Script language commands
  20.  
  21.  
  22.  
  23. 1: Overview of Message Templates
  24. --------------------------------
  25.  
  26. Imagine that you're the web master for your Internet site; you receive a
  27. huge amount of mail for much of which the answer is essentially the
  28. same... You laboriously reply to the message, remove the pieces you don't
  29. want, type in your canned response, then send the message. Wouldn't it be
  30. good if there was some way of automating all of this? Well, there is --
  31. Message Templates.
  32.  
  33. A Message Template is simply a script that tells Pegasus Mail how to
  34. compose a mail message. The template script commands allow you to set any
  35. address or feature field, include the original message for replies (or a
  36. portion of the message), change or modify addresses, add attachments and
  37. generally give you complete control over the shape of your automatically-
  38. generated message. What's even better, you can define variables in
  39. templates: when you use the template, Pegasus Mail will prompt you for
  40. values for the variables it contains; the script language can then take
  41. the values you enter, manipulate them, and insert them seamlessly into
  42. the generated message.
  43.  
  44. Using a message template, you can generate a complex mail message and
  45. send it with only a couple of keystrokes.
  46.  
  47. What uses might you have for a template? Here are some ideas:
  48.  
  49.    * Helpdesk submissions (as per the sample HELPDESK.PM5 template)
  50.  
  51.    * Mail server management forms (to simplify the process of
  52.      subscribing to and unsubscribing from lists)
  53.  
  54.    * Forms: any kind of complex data-entry based mail form could
  55.      be generated using a template
  56.  
  57.    * Order submission
  58.  
  59.    * Automated replies
  60.  
  61.  
  62. 2: Types of templates
  63. ---------------------
  64.  
  65. Pegasus Mail supports two types of templates - those used to create new
  66. messages from scratch, and those used to create replies to messages.
  67. Template files are simply plain text files containing template script
  68. language commands, one per line.
  69.  
  70. Templates used to create new messages have the extension .PM5; the name
  71. portion can be anything you wish.
  72.  
  73. Templates used to create replies to messages have the extension .PM6; once
  74. again, the name portion can be anything you wish.
  75.  
  76. For both types of template, the script language's TITLE command must be
  77. the first line in the file, so that Pegasus Mail can show the name in its
  78. selector window. Pegasus Mail will not burrow through a template file
  79. looking for a TITLE command if it is not on the first line.
  80.  
  81. Template files can be located in your home mailbox directory, or may be
  82. placed in the same directory as the Pegasus Mail executable program, in
  83. which case they become system-wide and are made available to all users
  84. running that copy of the program. There is no effective limit on the 
  85. number of templates you can define.
  86.  
  87. For now, in order to create a template file you must use a text editor of
  88. some kind - for instance, the Windows NOTEPAD applet. If you use NOTEPAD,
  89. make sure that the Wordwrap option is turned off - each line in a
  90. template file must contain a single command and you cannot run lines 
  91. together. Future versions of Pegasus Mail may include a user-interface for
  92. creating template files.
  93.  
  94.  
  95. 3: Using templates within Pegasus Mail
  96. --------------------------------------
  97.  
  98. You can create a new message using a template by selecting Template...
  99. from the New Message submenu of the File menu. This will open a dialog
  100. listing all the templates available on your system. Select the template
  101. you want to use by highlighting it and clicking Open, or by double-
  102. clicking it. A window will open prompting you for any variables the
  103. template uses; at this point, you can choose whether to open a new
  104. message editor window filled out with the message created by the
  105. template, or simply to send the message without further ado.
  106.  
  107. You can use a template to create a reply to a message in one of two ways:
  108.  
  109. 1: Right-click the message and choose "Reply using template..." from
  110.    the popup menu
  111.  
  112. 2: Highlight the message, then hold down <Shift> as you press the
  113.    "Reply" button, or else hold down <Shift> and press the R key.
  114.  
  115.  
  116.  
  117. 4: The Message Template Script Language
  118. ---------------------------------------
  119.  
  120. The script language used by Pegasus Mail templates is very simple. Each
  121. command in the file must appear on a single line of its own -- commands
  122. may not wrap lines, nor may more than one command appear on a single
  123. line. Lines starting with \, * ; or # are treated as comments and are
  124. ignored.
  125.  
  126.  
  127. 4.1: String literals
  128.  
  129. Most template script commands in the language accept strings as
  130. parameters. String literals of this kind must be entered in quote
  131. characters if they contain spaces or special characters.
  132.  
  133. For example, if you want to use the "insert" command to write the string
  134.  
  135.    Mary had a little lamb
  136.  
  137. into an outgoing message, you would need to enter the command like this:
  138.  
  139.    insert "Mary had a little lamb"
  140.  
  141. since otherwise, only the word "Mary" would be inserted.
  142.  
  143. If your string contains a quote character, or a backslash character, then
  144. you will need to perform a small amount of conversion. So, if you want to
  145. insert the string
  146.  
  147.    Mary had a "little" lamb
  148.  
  149. you would have to enter the "insert" command like this:
  150.  
  151.    insert "Mary had a \"little\" lamb"
  152.  
  153. These rules for string construction apply in all places throughout the
  154. script language.
  155.  
  156.  
  157. 4.1.1: Filenames
  158.  
  159. Filenames are treated as strings by the script language, and as such are
  160. subject to the same rules. In particular note that long filenames
  161. containing spaces will need to be quoted, and that '\' characters will
  162. need to be doubled in file paths... So, if you wanted to use the include
  163. command to include the file 
  164.  
  165.    c:\docs\Mary's "little" lamb
  166.  
  167. You would need to form the command as
  168.  
  169.    include "c:\\docs\\Mary's \"little\" lamb"
  170.  
  171.  
  172. 4.2: Optional parameters
  173.  
  174. Some script commands are shown as having "optional" parameters. This
  175. notion needs some clarification... A parameter may be omitted only if all
  176. the parameters following it are also omitted - it is not possible to omit
  177. only one parameter from the middle of a list.
  178.  
  179. So, using the "include" command as an example, if you wanted to include a
  180. file in quoted format, you would have to include the "0" value for the
  181. count parameter as well.
  182.  
  183.  
  184. 4.3: Command substitutions
  185.  
  186. Practically any string parameter to a script command can contain command
  187. substitutions: these are special character sequences that are replaced by
  188. variables or other information when they are encountered. Pegasus Mail
  189. recognizes the following command substitutions in any place where they
  190. may be used:
  191.  
  192.    ~vvariable_name~   The current value of a template script variable
  193.    ~z                 A single newline (CR/LF)
  194.    ~f                 The "from" field of the original message
  195.    ~s                 The "subject" field of the original message
  196.    ~r                 The preferred reply address for the message
  197.    ~kfieldname~       Any field from the original message
  198.    ~n                 The current user's basic username
  199.    ~i                 The current user's Internet e-mail address
  200.    ~8                 The current user's username truncated to 8 chars
  201.    ~p                 The current user's personal name preference
  202.    ~d                 A random integer expressed as 4 hex digits
  203.    ~y                 The current date and time in RFC822 format
  204.    ~%name%            The value of environment variable %name%
  205.    ~lname~l           The user's address looked up from a synonym file
  206.    ~a                 The Pegasus Mail executable directory
  207.    ~h                 The current user's home mailbox
  208.    ~w                 The current user's new mailbox
  209.    ~~                 A single tilde (~).
  210.  
  211. Examples:
  212.  
  213.    Assuming that the current user's name is "david" and the variable
  214.    "sub" has been assigned the value "your order", the string
  215.  
  216.       "This is a message from ~8, regarding ~vsub~"
  217.  
  218.    would yield the following string after substitution:
  219.  
  220.       "This is a message from david, regarding your order."
  221.  
  222. Command substitution is the single most powerful feature of the scripting
  223. language used for templates, and a good understanding of what it can do
  224. is essential for writing useful scripts.
  225.  
  226.  
  227. 4.4: Script language commands
  228.  
  229. The following commands are valid in template scripts.
  230.  
  231.    title      Set the title for a template script
  232.    helpfile   Set the help file for a template script
  233.    picture    Add a picture to the variable prompt dialog
  234.    text       Add a line of informational text to the prompt dialog
  235.    option     Set options controlling the way the template is processed
  236.  
  237.    string     Create a string variable for the script
  238.    set        Set a message field or variable value
  239.    insert     Write a formatted line into the message body
  240.    include    Include a file or the original message body
  241.    attach     Attach a file to the message
  242.  
  243.    extract    Extract elements from an e-mail address
  244.    lookup     Look up an item from a list using a key value
  245.  
  246.    chain      Execute another template when the current template finishes
  247.  
  248.  
  249. # title <string>
  250.  
  251. Set the title for the script file. string can be any string up to 50
  252. characters in length, and can contain all command substitutions except
  253. for variables, which are not defined at the time this command is
  254. processed.
  255.  
  256.  
  257. # helpfile <filename> [section]
  258.  
  259. Set the help file which should be accessed when the user clicks the Help
  260. button in the variable prompt dialog. filename should be a full reference
  261. to any valid Windows Help file (*.HLP) on your system, and may contain
  262. all command substitions except for variables, which will have not been
  263. defined at the time this command is processed. section is an optional
  264. integer value that indicates the context help section within the help
  265. file that should be presented when the help button is pressed. If it is
  266. absent, section 0, the table of contents, is presented.
  267.  
  268.  
  269. # option <option_name> = <value>
  270.  
  271. This command controls aspects of the way the template behaves as it is
  272. being processed. One option_name value is currently defined:
  273.  
  274.    "EDITOR" = "Yes" or "No".
  275.    - Determines the state of the "Send message without opening a message
  276.      editor" control in the template's variable dialog.
  277.  
  278.    Example:  OPTION EDITOR = NO
  279.    - Checks the "send without editor" control by default.
  280.  
  281.  
  282. # string <name> ["Default"] ["Prompt"] [len] [flags]
  283.  
  284. Define a variable for use within the script. A maximum of 20 variables
  285. may be defined for any script. name is the name for the variable; it must
  286. not contain spaces, and is not case-sensitive (so var1 and VAR1 are
  287. considered the same). All the parameters following the name parameter are
  288. optional, and you can end the string early if you wish (you cannot omit a
  289. parameter if you need to supply a parameter following it on the line).
  290. "default" is a string which should be used as a default value for the
  291. variable: if it contains spaces or special characters, it must be
  292. enclosed in quotes (see "String literals", above, for more information).
  293. If this parameter is omitted, the default value is an empty string.
  294. "prompt" is the string Pegasus Mail should place next to the editing field
  295. in the variable prompt dialog. If omitted or zero-length, Pegasus Mail
  296. will not prompt the user for a value for this variable. "len" is an integer
  297. defining the maximum allowable length of this variable. If omitted, the
  298. default is "no limit". "flags" defines the format and type of the variable:
  299. the following flag values are available:
  300.  
  301.    multiline       creates a multi-line variable
  302.    address         creates an e-mail address variable
  303.    filename        creates a filename variable
  304.    password        creates a password variable
  305.    list            creates a list - see below for more details
  306.    uppercase       specifies that the variable must be all in uppercase
  307.  
  308. Only "uppercase" may be used with other values.
  309.  
  310.  
  311. Creating LIST variables
  312.  
  313. When you use the LIST flag in a STRING statement, you create a variable
  314. that has a list of possible values from which the user can select. LIST
  315. variables require that you provide a DEFAULT value for the variable,
  316. which contains the list of possible values the variable can have. The
  317. first character in the default value should be the character used to
  318. separate the list items from each other, and the remainder of the default
  319. value should be the items, separated by that character.
  320.  
  321. Example: you want to allow the user to select from the values "Red",
  322. "Green" and "Blue": your string statement would look like this:
  323.  
  324.    string v1 ";Red;Green;Blue" "Select a colour" 0 list
  325.  
  326.  
  327. # set <field> = <"value">
  328. or set variable <variable_name> = <"value">
  329.  
  330. The first form of this command sets a field within the mail message being
  331. generated to the specified value. field may be one of the following: 
  332.  
  333.    to
  334.    cc
  335.    bcc
  336.    reply-to
  337.    subject 
  338.    identity      (all take an obvious string parameter)
  339.  
  340.    urgent
  341.    confirm-reading
  342.    confirm-delivery
  343.    copyself
  344.    volatile
  345.    mime          (all take either a "Y" or "N" parameter)
  346.    
  347.    header        (a fully-formed e-mail header including the keyword)
  348.    encrypted     ("encryptor_name", "password", "flags" - see below
  349.                   for more details).
  350.  
  351. When encrypting a template message, use the "encrypted" parameter to the
  352. set command. "encryptor" is the name of the module that should be used
  353. for encryption - to use the Pegasus Mail built in encryptor, use the name
  354. "builtin". "password" is the password for the message - this can be up to
  355. 96 characters in length. "flags" controls the type of encryption
  356. performed; to encrypt a message, set it to 1; to add a digital signature
  357. to the message, set it to 4; to perform both operations, set it to 5.
  358.  
  359. The "volatile" parameter tells Pegasus Mail to write the message directly
  360. to final form when sending using the built-in SMTP transport. You will
  361. need to set this to "Y" if you are attaching files that will be deleted
  362. once the template has been processed.
  363.  
  364. The second form of the "set" command sets the value of any defined
  365. variable.
  366.  
  367. Both forms of this command support all command substitutions for the value
  368. parameter. To copy the value of one variable to another, use an
  369. expression containing the ~v command substitution, like this:
  370.  
  371.    set variable v1 = "~vv2~"
  372.  
  373.  
  374. # insert <"string">
  375.  
  376. Write data into the body of the message being generated. string can
  377. contain any command substitution: if it does not contain a ~z
  378. substitution to force a line break, then the next insert command will
  379. write data onto the same line in the body. A single insert command may
  380. not insert more than 1024 characters into the message body.
  381.  
  382.  
  383. # include <filename> [count] [flags]
  384. or include message [count] [flags]
  385.  
  386. Include either a text file, or the body from the message to which a reply
  387. is being generated. The text from the file or message is included as-is
  388. into the message body - command substitutions are not performed on the
  389. included data. The filename parameter may contain any valid command 
  390. substitutions. If "count" is present and non-zero, only that many lines of
  391. the included file or the body of the included message will be read. The
  392. "flags" item can be any combination of the following values:
  393.  
  394.    quoted     "Comment-out" the included text using "> "
  395.    noheaders  If the file is a message, omit its RFC822 headers
  396.    keyheaders If the file is a message, include only "significant" headers
  397.    nobody     If the file is a message, omit the message body
  398.    message    Only valid for files: the file is an RFC822 message
  399.  
  400.  
  401. # attach <filename> [type] [encoding] ["Desc"]
  402.  
  403. Attach a file to the generated message. Only "filename" is a mandatory
  404. parameter - the others can be omitted and are sensibly defaulted. Any
  405. valid command substitution can be used in the filename. If the filename
  406. contains spaces, it must be quoted. "type" is any string describing the 
  407. type of the file - for instance, "RTF_FILE". It must not contain spaces
  408. and is not constrained to the list of possible values inside Pegasus Mail
  409. itself. "encoding" is an integer value that specifies how the file should
  410. be encoded for transfer; the following values are defined - 0 (Pegasus
  411. Mail decides), 1 (No encoding - very dangerous), 2 (ASCII text), 3
  412. (UUencoding), 4 (BinHex 4.0) and 5 (Basic MIME encoding). Unless you are
  413. sure of what you are doing, use 0 for this field. "desc" is a textual
  414. description of the file; it may contain any text, including spaces, and
  415. is truncated at 63 characters.
  416.  
  417.  
  418. # picture <flags> <filename>
  419.  
  420. Add a picture at the top of the variable prompt dialog. The picture
  421. specified by filename must be a Windows BMP file in 16 or 256 colours:
  422. owing to quirks in the way Windows handles 256 colour bitmaps, we
  423. strongly recommend that you use 16-colour bitmaps if your display runs in
  424. 256 colour mode or lower. For the Win16 version of Pegasus Mail, the
  425. bitmap must not be larger than 60,000 bytes. You may use any command
  426. substitution in the filename parameter. The bitmap is centred 
  427. horizontally in the display and the dialog will adjust size to fit the
  428. vertical dimensions of the image. Exactly one image may be added to the
  429. dialog.
  430.  
  431. flags will be used in future to offer extra formatting options. For now,
  432. it is unused, must be present, and should be set to zero.
  433.  
  434. Note: if the filename contains spaces or special characters, it must be
  435. enclosed in quotes.
  436.  
  437.  
  438. # text <flags> <"string">
  439.  
  440. Add a line of descriptive text to the dialog presented to prompt for
  441. script variables. The line of text is added above any variable editing
  442. fields, and below any picture defined using a picture command. You may
  443. specify up to 10 lines of descriptive text, and each line may contain any
  444. valid command substitution. The "flags" parameter will be used in future,
  445. but should currently be set to zero.
  446.  
  447. To introduce a blank line between groups of lines, use a text statement
  448. with an empty quoted string - like this: text "".
  449.  
  450.  
  451. # extract address <var1> <var2>
  452. or extract text <var1> <var2>
  453. or extract user <var1> <var2>
  454. or extract domain <var1> <var2>
  455.  
  456. Extract a component from an e-mail address. "var1" refers to the variable
  457. containing the address to be manipulated. "var2" is the variable where
  458. the result of the manipulation should be placed - it can be the same as
  459. "var1".
  460.  
  461.    extract address    yields the minimum form of the e-mail address
  462.    extract text       yields the personal name field from the address
  463.    extract user       yields the simple user name portion of the address
  464.    extract domain     yields the domain portion of the address
  465.  
  466.  
  467. # lookup "string" <var1> <var2> <var3>
  468.  
  469. Attempt to locate the string "string" in the list variable "var1"; if a
  470. match is found, note the position in the list where the item was matched,
  471. then copy the item at the same ordinal position in the list variable
  472. "var2" into the variable "var3". See above under the description of the
  473. "set" command for more information on list variables. It is an error for
  474. either "var1" or "var2" to be anything other than a list variable. If
  475. "string" cannot be found in "var1", variable "var3" is not changed.
  476.  
  477. Example: list variable "v1" contains "Monday", "Tuesday" and "Wednesday"
  478. list variable "v2" contains "Open", "Closed" and "Open".
  479.  
  480. The command
  481.  
  482.    lookup "Tuesday" v1 v2 v3
  483.  
  484. will result in variable v3 containing the value "Closed".
  485.  
  486. A common form of this command will use the current value of "var1" as the
  487. string parameter, using the command substitution "~vvar1~".
  488.  
  489.  
  490. # chain "filename"
  491.  
  492. Execute another template when the current template completes. "filename"
  493. should be the path to a valid template file, and may contain command
  494. substitutions. Only one "chain" command may be used per template. If the
  495. current template is cancelled by the user, the chain command will not be
  496. executed.
  497.  
  498.