Cleanup comments for nimdoc, add 'latest' Makefile task.
FossilOrigin-Name: 8835929c59b4fecb29f7bb2e96ca455ea17c4024839c8dce4c6ff01297c6594a
This commit is contained in:
parent
c3d931cb2e
commit
e87d791e54
6 changed files with 77 additions and 71 deletions
9
Makefile
9
Makefile
|
|
@ -23,8 +23,7 @@ release:dependencies ${FILES}
|
||||||
mv src/sieb .
|
mv src/sieb .
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
nim doc ${FILES}
|
nim doc --project --outdir:release/doc src/sieb.nim
|
||||||
mv src/htmldocs docs
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
fossil clean --dotfiles -f -v
|
fossil clean --dotfiles -f -v
|
||||||
|
|
@ -32,3 +31,9 @@ clean:
|
||||||
clobber:
|
clobber:
|
||||||
fossil clean -x -v
|
fossil clean -x -v
|
||||||
|
|
||||||
|
latest: clobber docs
|
||||||
|
tar -C .. --exclude .f\* -zcvf ../sieb-latest.tar.gz sieb
|
||||||
|
mkdir release
|
||||||
|
mv ../sieb-latest.tar.gz release
|
||||||
|
fossil uv add release/sieb-latest.tar.gz
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
# vim: set et nosta sw=4 ts=4 :
|
# vim: set et nosta sw=4 ts=4 :
|
||||||
|
|
||||||
#
|
##
|
||||||
# Methods for finding and parsing sieb rules from YAML.
|
## Methods for finding and parsing sieb rules from YAML.
|
||||||
#
|
##
|
||||||
|
|
||||||
#############################################################
|
|
||||||
|
#------------------------------------------------------------
|
||||||
# I M P O R T S
|
# I M P O R T S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
import
|
import
|
||||||
std/os,
|
std/os,
|
||||||
|
|
@ -18,9 +19,9 @@ import
|
||||||
import util
|
import util
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# C O N S T A N T S
|
# C O N S T A N T S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
const CONFFILES = @[
|
const CONFFILES = @[
|
||||||
"/usr/local/etc/sieb/config.yml",
|
"/usr/local/etc/sieb/config.yml",
|
||||||
|
|
@ -28,9 +29,9 @@ const CONFFILES = @[
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# T Y P E S
|
# T Y P E S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
type
|
type
|
||||||
Rule* = object
|
Rule* = object
|
||||||
|
|
@ -46,12 +47,12 @@ type
|
||||||
rules* {.defaultVal: @[]}: seq[Rule]
|
rules* {.defaultVal: @[]}: seq[Rule]
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# M E T H O D S
|
# M E T H O D S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
proc parse( path: string ): Config =
|
proc parse( path: string ): Config =
|
||||||
## Return a parsed configuration from yaml.
|
## Return a parsed configuration from yaml at `path`.
|
||||||
"Using configuration at: $#".debug( path )
|
"Using configuration at: $#".debug( path )
|
||||||
let stream = newFileStream( path )
|
let stream = newFileStream( path )
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
# vim: set et nosta sw=4 ts=4 :
|
# vim: set et nosta sw=4 ts=4 :
|
||||||
#
|
##
|
||||||
# A global logger. Just write stuff to disk safely.
|
## A global logger. Just write stuff to disk safely.
|
||||||
#
|
##
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# I M P O R T S
|
# I M P O R T S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
import
|
import
|
||||||
std/math,
|
std/math,
|
||||||
|
|
@ -16,28 +16,25 @@ import
|
||||||
std/times
|
std/times
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# T Y P E S
|
# T Y P E S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
type Logger = object
|
type Logger = object
|
||||||
fh: File
|
fh: File
|
||||||
start: MonoTime
|
start: MonoTime
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# G L O B A L E X P O R T S
|
# G L O B A L E X P O R T S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
var logger*: Logger
|
var logger*: Logger ## The exported logger object.
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
|
||||||
# M E T H O D S
|
|
||||||
#############################################################
|
|
||||||
|
|
||||||
proc createLogger*( parentdir: string, filename: string ): void =
|
proc createLogger*( parentdir: string, filename: string ): void =
|
||||||
## Get in line to open a write lock to the configured logfile at +path+.
|
## Get in line to open a write lock to the configured logfile at
|
||||||
|
## `filename` under `parentdir` directory.
|
||||||
## This will block until it can get an exclusive lock.
|
## This will block until it can get an exclusive lock.
|
||||||
let path = joinPath( parentdir, filename )
|
let path = joinPath( parentdir, filename )
|
||||||
try:
|
try:
|
||||||
|
|
@ -62,12 +59,12 @@ proc close*( l: Logger ): void =
|
||||||
|
|
||||||
|
|
||||||
proc closed*( l: Logger ): bool =
|
proc closed*( l: Logger ): bool =
|
||||||
## Returns +false+ if the logfile has been opened.
|
## Returns `false` if the logfile has been opened.
|
||||||
return l.fh.isNil
|
return l.fh.isNil
|
||||||
|
|
||||||
|
|
||||||
proc log*( msg: string ): void =
|
proc log*( msg: string ): void =
|
||||||
### Emit a line to the logfile.
|
## Emit a line to the logfile.
|
||||||
if logger.closed: return
|
if logger.closed: return
|
||||||
logger.fh.writeLine( msg )
|
logger.fh.writeLine( msg )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
# vim: set et nosta sw=4 ts=4 :
|
# vim: set et nosta sw=4 ts=4 :
|
||||||
#
|
|
||||||
# A class that represents an individual Maildir, and a Nessage class to nanage
|
|
||||||
# files underneath them.
|
|
||||||
#
|
|
||||||
|
|
||||||
#############################################################
|
##
|
||||||
|
## A class that represents an individual Maildir, and a Message class to nanage
|
||||||
|
## files underneath them.
|
||||||
|
##
|
||||||
|
|
||||||
|
#------------------------------------------------------------
|
||||||
# I M P O R T S
|
# I M P O R T S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
import
|
import
|
||||||
std/os,
|
std/os,
|
||||||
|
|
@ -24,9 +25,9 @@ import
|
||||||
util
|
util
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# C O N S T A N T S
|
# C O N S T A N T S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
const
|
const
|
||||||
OWNERDIRPERMS = { fpUserExec, fpUserWrite, fpUserRead }
|
OWNERDIRPERMS = { fpUserExec, fpUserWrite, fpUserRead }
|
||||||
|
|
@ -36,14 +37,14 @@ const
|
||||||
BUFSIZE = 8192 # reading and writing buffer size
|
BUFSIZE = 8192 # reading and writing buffer size
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# T Y P E S
|
# T Y P E S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
# A Maildir object.
|
# A Maildir object.
|
||||||
#
|
#
|
||||||
type Maildir* = ref object
|
type Maildir* = ref object
|
||||||
path*: string # Absolute path to the encapsualting dir
|
path*: string ## Absolute path to the encapsuating dir
|
||||||
cur: string
|
cur: string
|
||||||
new: string
|
new: string
|
||||||
tmp: string
|
tmp: string
|
||||||
|
|
@ -63,13 +64,12 @@ var
|
||||||
msgId = "" # The parsed Message-ID
|
msgId = "" # The parsed Message-ID
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# M E T H O D S
|
# M E T H O D S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
#------------------------------------------------------------
|
|
||||||
# Maildir
|
# Maildir
|
||||||
#------------------------------------------------------------
|
#------------
|
||||||
|
|
||||||
proc newMaildir*( path: string ): Maildir =
|
proc newMaildir*( path: string ): Maildir =
|
||||||
## Create and return a new Maildir object, making it on-disk if necessary.
|
## Create and return a new Maildir object, making it on-disk if necessary.
|
||||||
|
|
@ -95,9 +95,8 @@ proc subDir*( dir: Maildir, path: string ): Maildir =
|
||||||
result = newMaildir( dir.path & "/" & path )
|
result = newMaildir( dir.path & "/" & path )
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------
|
|
||||||
# Message
|
# Message
|
||||||
#------------------------------------------------------------
|
#------------
|
||||||
|
|
||||||
proc newMessage*( dir: Maildir ): Message =
|
proc newMessage*( dir: Maildir ): Message =
|
||||||
## Create and return a Message - an open FileStream under a specific Maildir
|
## Create and return a Message - an open FileStream under a specific Maildir
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
# vim: set et nosta sw=4 ts=4 :
|
# vim: set et nosta sw=4 ts=4 :
|
||||||
#
|
|
||||||
# Various helper functions that don't have a better landing spot.
|
|
||||||
#
|
|
||||||
|
|
||||||
#############################################################
|
##
|
||||||
|
## Various helper functions that don't have a better landing spot.
|
||||||
|
##
|
||||||
|
|
||||||
|
#------------------------------------------------------------
|
||||||
# I M P O R T S
|
# I M P O R T S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
import
|
import
|
||||||
std/parseopt,
|
std/parseopt,
|
||||||
|
|
@ -16,12 +17,12 @@ import
|
||||||
logging
|
logging
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# C O N S T A N T S
|
# C O N S T A N T S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
const
|
const
|
||||||
VERSION = "v0.1.0"
|
VERSION = "v0.1.0" ## The current Sieb version
|
||||||
USAGE = """
|
USAGE = """
|
||||||
./sieb [-c] [-d] [-h] [-v]
|
./sieb [-c] [-d] [-h] [-v]
|
||||||
|
|
||||||
|
|
@ -114,9 +115,9 @@ const
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# T Y P E S
|
# T Y P E S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
type Opts = object
|
type Opts = object
|
||||||
config*: string # The path to an explicit configuration file.
|
config*: string # The path to an explicit configuration file.
|
||||||
|
|
@ -124,16 +125,16 @@ type Opts = object
|
||||||
logfile*: string # Log actions to disk.
|
logfile*: string # Log actions to disk.
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# G L O B A L E X P O R T S
|
# G L O B A L E X P O R T S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
var opts*: Opts
|
var opts*: Opts ## Parsed command line options.
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# M E T H O D S
|
# M E T H O D S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
proc hl( msg: string, fg: ForegroundColor, bright=false ): string =
|
proc hl( msg: string, fg: ForegroundColor, bright=false ): string =
|
||||||
## Quick wrapper for color formatting a string, since the 'terminal'
|
## Quick wrapper for color formatting a string, since the 'terminal'
|
||||||
|
|
@ -152,7 +153,7 @@ proc deferral*( msg: string ) =
|
||||||
|
|
||||||
|
|
||||||
proc debug*( msg: string, args: varargs[string, `$`] ) =
|
proc debug*( msg: string, args: varargs[string, `$`] ) =
|
||||||
## Emit +msg+ if debug mode is enabled, coercing arguments into a string for
|
## Emit `msg` if debug mode is enabled, coercing arguments into a string for
|
||||||
## formatting.
|
## formatting.
|
||||||
if opts.debug or not logger.closed:
|
if opts.debug or not logger.closed:
|
||||||
var str = msg % args
|
var str = msg % args
|
||||||
|
|
@ -161,7 +162,7 @@ proc debug*( msg: string, args: varargs[string, `$`] ) =
|
||||||
|
|
||||||
|
|
||||||
proc parseCmdline*() =
|
proc parseCmdline*() =
|
||||||
## Populate the opts object with the user's preferences.
|
## Populate the global opts object with the user's preferences.
|
||||||
|
|
||||||
# Config object defaults.
|
# Config object defaults.
|
||||||
#
|
#
|
||||||
|
|
|
||||||
15
src/sieb.nim
15
src/sieb.nim
|
|
@ -1,8 +1,11 @@
|
||||||
# vim: set et nosta sw=4 ts=4 :
|
# vim: set et nosta sw=4 ts=4 :
|
||||||
|
##
|
||||||
|
## Primary logic for a single email delivery.
|
||||||
|
##
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# I M P O R T S
|
# I M P O R T S
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
import
|
import
|
||||||
std/exitprocs,
|
std/exitprocs,
|
||||||
|
|
@ -15,9 +18,9 @@ import
|
||||||
lib/util
|
lib/util
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# S E T U P
|
# S E T U P
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
# Without this, we got nuthin'!
|
# Without this, we got nuthin'!
|
||||||
if not existsEnv( "HOME" ):
|
if not existsEnv( "HOME" ):
|
||||||
|
|
@ -39,9 +42,9 @@ var finalTasks = proc: void =
|
||||||
finalTasks.addExitProc
|
finalTasks.addExitProc
|
||||||
|
|
||||||
|
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
# M A I N
|
# M A I N
|
||||||
#############################################################
|
#------------------------------------------------------------
|
||||||
|
|
||||||
# Parse the YAML ruleset.
|
# Parse the YAML ruleset.
|
||||||
let conf = getConfig( opts.config )
|
let conf = getConfig( opts.config )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue