run blogofile without installing

categories: tutorial

I normally dont install software that is not packaged as a debian package to not mess up my system. So when I decided for blogofile as the html generator for this "blog" I didnt want to do different. I followed these steps:

git clone https://github.com/EnigmaCurry/blogofile.git blogofile
mkdir target
cd target
export PYTHONPATH=../blogofile
python -c "from blogofile import main; main.main()" init simple_blog
python -c "from blogofile import main; main.main()" build
python -c "from blogofile import main; main.main()" serve

In the future blogofile's setup.py should get a prefix option or a target that just builds but doesnt install but I'm too lazy to implement that now.

View Comments

disposable email

categories: code

Signing up for a new random internet service (maybe to just try it out or to use it only once ie. to post one message to a forum) is usually a hassle because they all want a valid email address to "verify" your identity. Now since you wouldnt want to hand out your private email address to everybody you could have a second email account at a big provider where you dont care about the spam they may subsequently send you but if you use it for a lot of services the spam easily gets out of hand (also it's not really geeky since everybody does it like that). You could also set up your own email server and create a new account for every website you want to register to. This would have the advantage that you can easily disable that account once it receives spam or once you dont need it anymore - leaving others intact. Or you could even find out if someone gave your email to someone else. Suppose you want to register at foobar.com so you create the account foobar_com@myserver.org. If you later on receive emails from someone totally different on that address you can be sure that foobar.com gave your address to someone else as they are the only ones (besides yourself) that know about it. That approach has the disadvantage though that setting up a new account requires some extra work that you have to go through again and again - even when it is only calling one script that does it for you. You of course want something totally automated without any manual labour.

A solution for that would be Disposable email addresses. You would just pick a website that offers this service, pick an address nobodye else used yet and give it to the internet service you want to register to and afterward you can just pick up the mail that was sent to that disposable email service provider. It has the advantage that the address you use doesnt have to be set up priorly - those services will just catch any mail they get and make them public under their respective addresses. Another advantage would be that again you easily see whether someone gives your email away (as with the solution of using your own email server). A disadvantage is that the address you want to use might already be picked by someone else, so if you want to use the address foobar_com@disposableprovider.org, someone else might given that address to foobar.com so you cant register at it with that address and have to pick a new one that is harder for you to remember. Also, those disposable email service providers mostly dont require you to sign up with them. As a result you have to keep track of all the addresses you use by yourself. The biggest disadvantage though is that most internet service providers (naturally) dont want you to give them a disposable email address so they would block every disposable email provider you can find with an internet search.

Now I needed a disposeable email solution with all the advantages of the above without the disadvantages, so i programmed my own little email server that would handle disposable email and would of course not be blacklisted by the big providers. I would also have the advantage of using this service only myself so that there would be no clashes of addresses I want to use but were used by somebody else before. And additionally I could always get a list of all addresses I ever used easily and manage them.

It turned out to be really easy to do in python and here is the server script that i now use for half a year on mister-muffin.de:

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python

from smtpd import SMTPServer
import asyncore
from email import message_from_string
import os
from datetime import datetime

#ripped out of mimetypes.MimeTypes().types_map_inv
exts = {
[...]
}

class DisposableMailServer(SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
rcpttos = [x[:-17] for x in rcpttos
if x.endswith('@mister-muffin.de')
and len(x)>17]
if not rcpttos:
return None

print "new mail for", rcpttos

msg = message_from_string(data)
basepath = '/directory/where/to/put/all/your/email/in'
counter = 1
now = datetime.now().isoformat()
header, _ = msg.as_string().split('\n\n', 1)

for name in rcpttos:
path = os.path.join(basepath, name, now)
if not os.path.exists(path):
os.makedirs(path)

with open(os.path.join(path, "header.txt"), "w") as f:
f.write(header)

for part in msg.walk():
if part.get_content_maintype() == 'multipart':
continue

filename = part.get_filename()

if not filename:
ext = exts.get(part.get_content_type())
if not ext:
ext = '.bin'
filename = 'part-%03d%s'%(counter,ext)
else:
filename = 'part-%03d-%s'%(counter,filename)

filename = os.path.join(path, filename)

if part.get_payload(decode=True):
with open(filename, "w") as f:
f.write(part.get_payload(decode=True))

counter += 1

if __name__ == '__main__':
proxy = DisposableMailServer(("mister-muffin.de", 25), ("localhost", 25))
try:
asyncore.loop()
except KeyboardInterrupt:
pass

Of course this means that you can send any email to pickanything [at] mister-muffin.de and i will note about it - you have no idea how much email I get at josch [at] mister-muffin.de but i dont think i will ever use this address for real email. (I obfuscated these emails here, replacing @ by [at] and adding spaces so that search engines wont list those email addresses)

I was very surprised how simple it is to write something like that in python. What it does is to analyze all incoming email, create a new directory named by the sender in a target directory and save the email in a subdirectory named with a timestamp (which i thought would be unique enough). Inside that directory the script will place the raw email header for possible inspection and the payload which might be a text message, the same thing as html and any attachment that was sent.

The directory I chose is also published with my webserver so that I dont even need to ssh into my server to pick up email but just have to go to a certain url (which i'm not telling you because i want to keep using it for myself) and open the text or html of the mail.

Using it for youself is only a matter of fixing the basepath in line 25 and have it running on a public server of yours. I also didnt include the content of the ext variable in line 10 because it was too long but it is only a mapping of content type to file extension like:

exts = {
'application/andrew-inset': '.ez',
'application/annodex': '.anx',
'application/atomcat+xml': '.atomcat',
'application/atomserv+xml': '.atomsrv',
[...]

Have fun!

View Comments

gcc preprocessor website generation

categories: code

At some point I was helping a friend with doing a website for his stepfather. Since it was only five pages I wanted to have something very simple to generate html pages from a header, a body and footer where header and footer would of course be the same for every page.

My "brilliant" idea was to combine the gcc preprocessor with make to achieve this and here is the Makefile i wrote:

CC=gcc
CFLAGS=-x c -E -P

SOURCES:=$(wildcard *.tmpl)
INCLUDES:=$(wildcard *.incl)
OBJS:=$(patsubst %.tmpl, %.html, $(SOURCES))

all: $(OBJS)

%.html: %.tmpl $(INCLUDES)
$(CC) $(CFLAGS) -o $@ $<

.PHONY: clean
clean:
rm -f *.html

The CFLAGS are forcing gcc to treat the files as c code, to only run the preprocessor and to not generate line markers in the output.

Files named *.incl are for example header.incl and footer.incl and are included by *.tmpl files. Every *.tmpl file is turned into a *.html file and the *.tmpl files can contain statements like:

#include "header.incl"
<p>some text</p>
#include "footer.incl"

And of course due to the nature of make a *.html file will only be regenerated if one of it's dependendcies (the corresponding *.tmpl or one of the *.incl) change. No speed improvement for my five html pages setup but it's the idea that counts here ;)

View Comments

first post

categories: blog

first post.

read more about this website on the "About" page.

i will see to dump some stuff that already piled up in the next few weeks.

View Comments
Newer Entries ยป