I've created a simple mail to Freenet gateway which is written in Python. It is dependent on at least freenetlib.py version 0.03. It can currently not interpret MIME email, but I plan on implementing this very soon.
-- Travis Bemann Sendmail is still screwed up on my box. My email address is really bemann at execpc.com. -------------- next part -------------- #!/usr/bin/env python # A mail to Freenet gateway daemon. This is dependent on the module # freenetlib. This only works on fully Posix-compliant systems. # # mail2freenet.py 0.01 # # Copyright (C) 2000 Travis Bemann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # more information on Freenet is availiable at http://freenet.sourceforge.net/ import sys import os import freenetlib import string import cStringIO import pwd import rfc822 MAIL_SPOOL_DIR = '/var/spool/mail' class Mail2Freenet: def __init__(self): if len(sys.argv) == 2: self.server = sys.argv[1] self.port = 19114 elif len(sys.argv) == 3: self.server = sys.argv[1] try: self.port = int(sys.argv[2]) except KeyError: print 'Usage: %s [server [port]]' % sys.argv[0] sys.exit(1) elif len(sys.argv) > 3: print 'Usage: %s [server [port]]' % sys.argv[0] sys.exit(1) else: self.server = 'localhost' self.port = 19114 self.make_daemon() pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell = pwd.getpwuid(os.getuid()) self.mail_dir = '%s/%s' % (MAIL_SPOOL_DIR, pw_name) while 1: files = os.listdir(self.mail_dir) for file in files: self.transfir_mail(mail_dir + file) def transfer_mail(self, file): f = open(file, 'r') m = rfc822.Message(f, 1) subj = m.get('Subject', None) if subj != None: cont = cStringIO.StringIO() f.seek(0, 0) line = f.readline() while string.strip(line) != '': line = f.readline() line = f.readline() while line: cont.write(line) fn = freenetlib.Freenet(self.server, self.port, keep_alive = 0) fn.insert(subj, cont) fn.close() f.close() os.unlink(file) def make_daemon(self): pid = os.fork() if pid > 0: os._exit(0) elif pid < 0: print 'Unable to fork - exiting' sys.exit(1) if os.setsid() < 0: print 'os.setsid() failed - exiting' sys.exit(1) pid = os.fork() if pid > 0: os._exit(0) elif pid < 0: print 'Unable to fork - exiting' sys.exit(1) os.chdir('\') sys.stdout.close() sys.stdin.close() sys.stderr.close() os.open('/dev/null', os.O_RDWR) os.dup(0) os.dup(0) if __name__ == '__main__': mf = Mail2Freenet()
