====== SMBUTIL - Message Base Utility ======

The Synchronet Message Base Utility (''smbutil'') can be used for several things, but most importantly, it must be used for maintaining the message bases of your system's public message areas (sub-boards).

The ''m'' command (for //maintenance//) instructs smbutil to mark old messages, and messages over the maximum sub-board limit, as //deleted// so that the disk space used by these message can be allocated to new messages. If you are using the 'Hyper Allocation' or 'Fast Allocation' method for your message bases, you must also use this utility to pack your message bases periodically.  The pack (''p'') command instructs smbutil to compress the message bases, removing any unused allocation blocks (for messages marked as //deleted//).

smbutil maintenance and/or packing should be done using an //exclusive// daily timed event (configured in [[util:SCFG]]->External Programs->Timed Events).  If your message bases are using the 'Fast Allocation' or 'Hyper Allocation' storage methods, you should run maintenance before packing (there is no reason to pack if you do not run maintenance!). If your message bases are configured for the 'Self Packing' method, you do NOT need to use smbutil to pack, only to perform maintenance.

**Note**:
The ''mail'' base (the Synchronet message base for e-mail and all forms of netmail storage) is maintained nightly by the Synchronet Terminal Server. You should not normally need to use smbutil on your mail base.

=====Usage=====

smbutil operates on message base files only. It does not read Synchronet configuration files so therefore will not automatically know where to find the message base files (i.e. by default in ''[[dir:data]]/subs'' for sub-boards), unless:
  - The message base files (e.g. '*.shd') are in the current working directory, or
  - You specify the full path to the message base file(s) on the SMBUTIL command-line

**WARNING**:
All BBS nodes should be offline when using smbutil with the pack command!  To do this, set the smbutil event to be 'Exclusive' in the SCFG program.

==== Syntax ====

  smbutil [-opt] [-opt] cmd [cmd] <filespec.shd>

===Commands===

One or more commands (''cmd'' values) may be specified per invocation of smbutil.

<code>
       l[n] = list msgs/files starting at number n
       r[n] = read msgs/files starting at number n
       x[n] = dump msg index at number n
       v[n] = view msg headers starting at number n
       V[n] = view msg headers starting at number n verbose
       i[f] = import msg from text file f (or use stdin)
       e[f] = import e-mail from text file f (or use stdin)
       n[f] = import netmail from text file f (or use stdin)
       h    = dump hash file
       s    = display msg base status
       c    = change msg base status
       R    = re-initialize/repair SMB/status headers
       D    = delete and remove all msgs/files (not reversable)
       d    = flag all msgs/files for deletion
       u    = undelete all msgs/files (remove delete flag)
       m    = maintain base - delete old msgs/files and msgs over max
       p[k] = pack msg base (k specifies minimum packable Kbytes)
       Z    = lock a msg base SMB header for testing, until keypress
       L    = lock a msg base for exclusive-access/backup
       U    = unlock a msg base
</code>

Commands without values may be concatenated (e.g. ''mp'' is the equivalent of ''m p'').

== List ==

When listing messages. the displayed fields are:
| IndexNum/MsgNum | [DateTime] | [TimeZone] | FromName | ToName | Subject |

Vote messages (including polls and ballots) are listed with relevant details following ''*VOTE'', ''*POLL'', or ''*CLOSE-POLL''.

When listing files. the displayed fields are:
| IndeNum/FileNum | [DateTime] | [TimeZone] | FromName | ''*FILE'' | FileSize | FileName |

**Note:**\\
The [DateTime] and [TimeZone] fields are only included with increasing levels of verbosity (use of the ''-v'' option).

== Index ==

When dumping a message base index, the display fields are:

| IndexNum | [TypeCode] | FromHex | ToTex | SubjHex | AttrHex | IndexOffsetHex | DateTime |

When the record is **not** a message, the following TypeCode value mapping is displayed:
^ Code ^ Type ^
| V    | Ballot |
| P    | Poll |
| C    | Poll-closure |
| F    | File |

===Options===

Zero or more options (''opts'') may be specified per invocation of smbutil.

<code>
      -c[m] = create message base if it doesn't exist (m=max msgs)
      -a    = always pack msg base (disable compression analysis)
      -i    = ignore dupes (do not store CRCs or search for duplicate hashes)
      -d    = use default values (no prompt) for to, from, and subject
      -l    = LZH-compress message text
      -o    = print errors on stdout (instead of stderr)
      -p    = wait for keypress (pause) on exit
      -!    = wait for keypress (pause) on error
      -b    = beep on error
      -r    = display raw message body text (not MIME-decoded)
      -v    = increase verbosity of console output
      -C    = continue after some (normally fatal) error conditions
      -t<s> = set 'to' user name for imported message
      -n<s> = set 'to' netmail address for imported message
      -u<s> = set 'to' user number for imported message
      -f<s> = set 'from' user name for imported message
      -e<s> = set 'from' user number for imported message
      -s<s> = set 'subject' for imported message
      -z[n] = set time zone (n=min +/- from UT or 'EST','EDT','CST',etc)
      -U[n] = set umask to specified value (use leading 0 for octal, e.g. 022)
      -#    = set number of messages to view/list (e.g. -1)
</code>

====Examples====

=== Maintenance ===

for maintenance and packing (100k or more per sub):

  smbutil mp100 /sbbs/data/subs/*.shd

for maintenance only (self-packing sub-boards):

  smbutil m /sbbs/data/subs/*.shd


When using the pack command, smbutil will check to see if it is necessary for you to pack your message base, if you want to skip this checking and have it unconditionally pack the message base (useful when attempting to repair a corrupted message base), you should add the '-a' switch to the command line:

  smbutil -a p /sbbs/data/subs/*.shd

The maintenance and pack commands are likely all that you will ever need to use smbutil for.

=== Repair ===

If you have a message base that is severely corrupted (e.g. ''[[util:fixsmb]]'' cannot open it for index repair), you can use the following smbutil command-line to re-initialize the message base status header:

  smbutil -C Rcs /sbbs/data/subs/badbase
  
This command will instruct smbutil to:
  -continue upon error when opening a corrupted message base
  -re-initialize the SMB/status headers of the message base
  -change/configure the status header values (e.g. max messages, CRCs, age)
  -display the status header
  
After repairing a message base in this manner, you may still need to run ''[[util:fixsmb]]'' on it to resolve any remaining errors reported by ''[[util:chksmb]]''.

=== Auto-post ===

smbutil may be used for automated message posting (or email sending), by using the ''i'' command (or ''e'' command for e-mail), for example:

  smbutil -d i/path/to/msg.txt /sbbs/data/subs/subcode
  
You can override the default to/from/subject header field values by using the various command-line options (e.g. ''-t'', ''-f'', ''-s''). But note: when using a value that contains spaces (multiple words), you will need to enclose the option and value in quotes:

  smbutil -tAll "-fYour Sysop" "-sDaily Bulletin" i/path/to/msg.txt /sbbs/data/subs/subcode
  
**Note**:
Although message importing/auto-posting via smbutil is supported, the preferred solution is to use the ''[[module:postmsg]].js'' module (e.g. via [[util:JSexec]]).


===== See Also =====
  * [[util:index|Utilities]]
  * [[util:fixsmb]]
  * [[util:chksmb]]

{{tag>smb msgbase subs}}