MAILDROPGDBM(7)

✨ MAILDROPGDBM ✨ (that's the man page for maildropgdbm, section 7, bestie πŸ’…)

okay so real talk: this is the maildropgdbm(7) manual page, and it's all about how maildrop does that GDBM/DB database thing. come sit with me, we're gonna go through it together 🫢


🌸 NAME 🌸

maildropgdbm β€” GDBM/DB support in maildrop


πŸŽ€ SYNOPSIS πŸŽ€

gdbmopen(filename, mode)

gdbmclose

gdbmfetch(key [,default])

gdbmstore(key,value)

πŸ’– DESCRIPTION πŸ’–

so the gdbm fam of functions is your backstage pass to the GDBM library β€” and that's a library of routines that manage simple database files. what does it do? it gives you a way to quickly store and look up key/data pairs. speedy little key/value situation, obsessed. ✨

GDBM support in maildrop is optional, and honestly? it may not even be available to you. not everyone gets the invite.

GDBM support in maildrop can optionally be implemented using the DB library. this is a choice your system administrator makes β€” not you, not me, not the group chat. if that's the setup, these functions still work exactly as described down below, except they'll operate on DB hash files instead of GDBM files. same vibes, different file type πŸ’…

want to know whether GDBM or DB support is being used? run this:

maildrop -v

GDBM support is minimal, and simplistic. it's giving low-effort but it works. a filter file may have only one gdbm file open at the same time. one. that's it. however! the filter file can close the current gdbm file, and open another one. and if another filter file gets included using the include statement, that included filter file may open its own, separate, gdbm file. so it's one per filter file, not one globally. main character energy only for the current file 😌

a GDBM file contains a list of key/value pairs. all keys in the GDBM file are unique β€” no dupes allowed, we don't do that here. after storing an arbitrary key/value pair in the GDBM file, the value associated with the given key can be quickly located and retrieved. fast lookup, slay.

πŸ”’ gdbmclose β€” close gdbm file

gdbmclose

this function closes the current GDBM file. that's it. bye bestie πŸ‘‹

πŸ” gdbmfetch β€” retrieve data

gdbmfetch (key [, options] [, default])

this function retrieves the data for the given key. key is the key to retrieve. the gdbmfetch function returns the data associated with this key. if the key does not exist in the GDBM file, gdbmfetch returns the default argument. and if the default argument is not specified, gdbmfetch returns empty text. also β€” and this is the sneaky important part β€” please note that the default argument is not actually evaluated unless the key does not exist in the GDBM file. so it's lazy, but in the correct, efficient way. respect.

the options argument specifies additional maildrop value-added features. the following functionality is not available in the GDBM library β€” it's actually provided by maildrop itself. maildrop said "I'll handle this one" πŸ’…

if the options argument is set to "D", and the key could not be found in the GDBM database, and the key is of the form "user@domain", maildrop will then attempt to look up the key "user@". if that key is also not found, maildrop finally looks up the key "domain". going down the list, one by one, no skipping.

if "domain" is also not found, and domain is of the form "a.b.c.d.tld" (with variable number of period-separated sections), maildrop then attempts to look up the key "b.c.d.tld". if that key is not found, maildrop tries "c.d.tld", and so on, until a key is found, or there are no more subdomains to remove β€” at which point gdbmfetch will return either the default argument, or empty text. it keeps going until it runs out of dots to drop. periodt.

if the options argument is set to "D", and the key could not be found in the GDBM database, and the key is of the form "a.b.c.d.tld" (with variable number of period-separated sections), maildrop will also attempt to look up keys for successive higher-level domains in the GDBM database. so many lookups, so little time.

Note πŸ“ GDBM databases are case sensitive. make sure that the GDBM database is created using lowercase letters only, and use the tolower function to convert the key to lowercase. case sensitivity is the villain here, no cap.

if the options argument is "I", and the key is not in the GDBM database, and the key is of the form "w.x.y.z" (with variable number of period-separated sections), maildrop then tries to look up the key "w.x.y", then "w.x", until a key is found, or there are no more sections to remove. use this feature to look up IP-address based GDBM lists. very IP-coded of you πŸ”₯

Note πŸ“ these features are implemented by brute force: if the query doesn't succeed, try again. take note of potential denial-of-service attacks where key is set to a long text string consisting mostly of periods, which will result in numerous GDBM queries that will take an excessive amount of time to complete. that's the opposite of slay, bestie. that's a whole flock of GDBM queries showing up uninvited πŸ’€

πŸšͺ gdbmopen β€” open gdbm file

gdbmopen (file [, mode])

gdbmopen opens the indicated GDBM file. the optional second argument specifies the following:

  • "R" β€” open this GDBM file for reading.
  • "W" β€” open this GDBM file for reading and writing.
  • "C" β€” open this GDBM file for reading and writing. if the GBDM file doesn't exist, create it.
  • "N" β€” create a new GDBM file. if the file exists, the existing file is deleted. the file is opened for reading and writing. (yes, deleted deleted. be so careful.)

the mode argument defaults to "R" is used. in embedded mode, only "R" is allowed. embedded mode said "read only, I don't have the range."

the GDBM library allows multiple processes to read the same GDBM file at the same time, but it does not allow multiple access when the GDBM file is open for writing. using flock or dotlock is highly recommended. like, seriously, do it. lock your files, protect your peace 🫢

in delivery mode, maildrop runs from the recipient's home directory. keep that in mind while specifying the filename β€” the where matters as much as the what, iykyk.

the gdbmopen function returns 0 if the GDBM file was successfully opened, non-zero otherwise. zero means we ate. πŸŽ€

πŸ’Ύ gdbmstore β€” store data

gdbmstore(key, value)

key is the key value to store in the GDBM file. value is the value to store. if key already exists in the GDBM file, value replaces the old value. out with the old, in with the new, glow-up behavior ✨

the gdbmstore function is only permitted if the GDBM file is opened for writing. if gdbmopen opened the GDBM file for reading only, gdbmstore will return -1. otherwise, gdbmstore returns 0. no write permission, no storing, that's the rule πŸ’…


πŸ‘‘ AUTHOR πŸ‘‘

Sam Varshavchik Author


πŸ“ NOTES πŸ“

  1. tolower http://www.courier-mta.org/maildrop/maildropfilter.html#tolower
  2. flock http://www.courier-mta.org/maildrop/maildropfilter.html#flock
  3. dotlock http://www.courier-mta.org/maildrop/maildropfilter.html#dotlock

and that's the whole page bestie!! this one came to you from Courier Mail Server, dated 01/10/2026 β€” so if you're reading it way later, it's giving vintage but it's still iconic. go forth, open those gdbm files responsibly, close them when you're done, and for the love of everything use flock or dotlock. mwah πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from
  • ubuntu stonking: maildrop 4.0.4-1 Β· GPL-3~with-OpenSSL-exception
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms