[Tutor] The use of MailDir for a mail server

dman dman@dman.ddts.net
Wed, 22 May 2002 11:26:33 -0500


--UHN/qo2QbUvPLonB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, May 20, 2002 at 12:47:11PM +0000, alex gigh wrote:
| Hi;
|=20
| I am still trying to write a mail server in Python... I decided that=20
| instead of going for the simple option of creating a file for each user a=
nd=20
| append each new message to this file, I will use "MailDir"...

Apart from error handling, mbox and maildir are both fairly easy to
implement.  I think maildir is actually a bit simpler.

| the problem is... I searched the web to find an example on how I
| could use this (my program is going to be a simple mail server with
| pre-defined 2 or 3 users.... ) but couldn't find anything useful.
| Can someone give me an example of :
|=20
| 1) how I can create these maildirs

One way to find this info is to use an existing program and see what
it does.  Here are some shell (works in bash with gnu utilities)
commands to make a maildir "folder" and put a new message in it :


mkdir -p the_folder/{new,cur,tmp}
cat > the_folder/new/some_unique_id_001 <<EOF
From: a user <me@here.com.invalid>
To: you <you@there.com.invalid>
Date: Wed May 22 11:22:28 CDT 2002
Subject: just a short test message

test
EOF


You can verify that this works by opening the folder with mutt (or any
other client).
=20
| 2) if i need to put a new message in there... how do I copy a new file in=
=20
| there

Same way you write any file.  Use the "open()" function to open the
file for writing and write your data to it.  If you already have the
data in a file somewhere use the appropriate function in the "shutils"
module.
=20
| 3) and finally, when delivering messages, how do I get the text from the=
=20
| possibly several different files

I don't understand this question.  How did the text get into multiple
files in the first place?  A mail message is (normally, who knows if
you use weird junk like MS Exchange or Lotus Notes) a single stream of
bytes.  A file is also a single stream of bytes, it is just connected
to the disk.

| Also... where exactly can I find the source code for the python libraries=
=20
| (namely smtp and rfc822) because I'm not allowed to use these...

In the python distribution.  It's all there.  (http://www.python.org)
The "Python Mail System" (http://pythonms.sf.net) project also has useful
code for handling maildir and mbox folders (and other stuff). =20
=20
| Many thanks for your time

HTH,
-D

--=20

"...In the UNIX world, people tend to interpret `non-technical user' as
meaning someone who's only ever written one device driver."
    --Daniel Pead
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


--UHN/qo2QbUvPLonB
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAjzrxrkACgkQO8l8XBKTpRQt7wCeMYHq0G8WpCRX6ccD3LEXVo32
Lf8AoJM4DJQKquhnLGzNK77p57Bk/K6a
=Mf7I
-----END PGP SIGNATURE-----

--UHN/qo2QbUvPLonB--