Skip to content
Gaute Hope edited this page Sep 29, 2015 · 11 revisions
A signature block (often abbreviated as signature, sig block, sig file,  
.sig, dot sig, siggy, or just sig) is a block of text automatically  
appended at the bottom of an e-mail message, Usenet article, or forum post. 

http://en.wikipedia.org/wiki/Signature_block

The default signature is specified on a per account base in sup's configuration. The :signature: configuration option expects a path to a text file containing the signature
Configuration Options.

The :edit_signature: configuration option enables or disables manual editing of the signature while a message is composed.

A more flexible approach to generate signatures is the signature hook:

File: /home/ruthard/.sup/hooks/signature.rb
Generates a message signature.
Variables:
      header: an object that supports string-to-string hashtable-style access
              to the raw headers for the message. E.g., header["From"],
              header["To"], etc.
  from_email: the email part of the From: line, or nil if empty
  message_id: the unique message id of the message
Return value:
  A string (multi-line ok) containing the text of the signature, or nil to
  use the default signature, or :none for no signature.

Signatures can be generated based on information in the From, To, Cc, Bcc or Subject header lines of the message.

example:

if header['To'] =~ /supmua/
  "sup rules!"
elsif header['To'] =~ /mutt/
  "mutt is the best!"
elsif header['To'] =~ /pine/
  "pine forever!"
else
  nil   # return nil to choose the default signature defined in config.yaml
end

Using sup's dialog functions (-> Interactive Hooks), it's possible to choose signatures manually:

This is an example of an interactive signature hook. It prompts the user for a keyword to choose the signature that should be used for this message

### signature.rb -- generate signature
### This example demonstrates how to generate the signature interactively


## Configuration

# Hash containing name => signature pairs
signatures = {
        "professional" => """
This is the Grand Professional Signature.
""",
        "familiar" => """
This is the Good Familiar Signature.
""",
        "private" => """
This is the Great Private Signature.
""",
        "no signature" => "",
}
# default signature key
default = "professional"
# prompt
prompt = "Choose signature"
help = "(<tab> for list of choices, empty line for #{default} signature)"


## Globals
# The signature hook is called every time the message has to be generated.
# we'll store our choice in a global hash with the message id as key
# to avoid being asked again and again 
$signature = {} unless $signature


## Logic
# ask for signature, if there is none stored for this message_id
signature_key = nil
unless $signature[message_id]
  # ensure signature_key is in signatures.keys
  until signatures.key? signature_key
    # use BufferManager's dialog function (compare lib/sup/buffer.rb)                  
    signature_key = BufferManager.ask_many_with_completions(
            :sign,           # token for BufferManager's sake.
            "#{prompt}: ",          # Prompt
            signatures.keys) # Array with posible completions
    # add help in case the first attempt was not successful
    prompt = "#{prompt} #{help}"
    # check for empty line and select default signature
    if signature_key  == ""
     signature_key = default
      break
    end
  end
 # store chosen signature in global variable for later reuse
  $signature[message_id] = signatures[signature_key]
end

# return chosen signature
$signature[message_id]
Clone this wiki locally