[Tutor] email anonymizing

Luke Paireepinart rabidpoobear at gmail.com
Fri Jul 14 06:25:00 CEST 2006


One way to do it:
have your form submit the body of the email,the email address, and a 
checkbox value of whether they want to anonymize it.
have a SQL table called Anonymize and if they want to anonymize the 
e-mail do
'SELECT anon FROM Anonymize WHERE email = %s' % email_from_form_submisson

to get the original email from the anonymous one do
'SELECT email FROM Anonymize WHERE anon = %s' % anon_email_value

beyond that, give us more info and we'll try to help.
Are you having trouble with SQL queries?  Are you having trouble with 
Python?
Are you having trouble with your SQL module in Python?
I suggest you try to write the program and when you get stuck,
try to find help in FAQs or the documentation of whichever module is 
giving you trouble,
and if you still can't determine what to do, we'll give ya a hand.

The thing is, there are a bunch of different ways you could do what 
you're trying to do.
First of all, you can use any database system you wanted, mySQL, 
PostgreSQL, MS ACCESS, etc etc.
Or you could even use single/multiple files, in single or multiple 
directories, depending.
You could try to anonymize the email client-side using Javascript or 
serverside using Python.

Why do you think Python is the best thing to user here?
It sounds like PHP would be better.  It's designed for this kind of thing.

You need to plan out what you're trying to do and figure out what the 
best solution is.
It's much easier for us to help you with the implementation when you 
have the design already.

That said, here's what I'd do (I don't have my Python Apache server 
running so this is going to be from memory I.E. probably not working code)
And it uses mysqldb because that's the database module I'm familiar with.

#!/usr/bin/python
#blah.cgi
#blah.cgi gets the user's e-mail address and anonymizes it.  Tru dat.

dbuser,dbpass = 'bob','pass'

print "Content-Type: text/plain\r\n\r\n"
print "<html><head><title='sample e-mail anonymizing skript'></head><body>"
import cgi, MySQLdb
from random import randint
info = cgi.FieldStorage()
try:
    #if this fails then this is their first time accessing the page.
    email=form.getfirst("email","").upper()
    #okay it didn't fail so we have their email now.
    #let's check the database to see if their email is there.
    database = MySQLdb.connect(host="localhost", user=dbuser,passwd=dbpass)
    cursor = database.cursor()
    cursor.execute('SELECT anon FROM Anonymize WHERE email = %s' % email)
    tmp = cursor.fetchall()
    if tmp == ():#or whatever the 'fetchall' method returns if it can't 
find the entry...  
       tmp = "%i at domain.com" % random.randint(1000,9999)#make their 
random address.
       #TODO: make sure the randomly-generated key here isn't already in 
use.
       cursor.execute("INSERT INTO Anonymize (email,anon) VALUES 
('%s','%s')" % (email,tmp))#adds their crap to the table.
   
    print "The e-mail address '%s' anonymized is '%s'" % (email,tmp)

except:
    print """
    <form>
       <input type='text' name='email' width=40></input>
       <input type='Submit' value='Login'></input>
    </form>
    """
print '</html>'

Hope that works.
Also, if you haven't already, you should read 
http://www.catb.org/~esr/faqs/smart-questions.html
-Luke

anil maran wrote:
> 1) how much programming experience you have.
> i have programmed in cfor about 1 year or so
> 2) how new to Python are you.
> very new 1 week
> 3) why do you want to solve this problem in Python?
> i m tryin to do a web app so i want to do in python
> 4) what can you apply from other languages you know (you refer to Java 
> and C++) to this problem
> i dont know how to go about this, and hence i was asking for possible solns from u guys
> 5) have you written any Python code toward solving this problem?
> no i havent 
> 6) do you need help in how to do string substitutions? how to randomly 
> generate names? how to store persistently and retrieve mappings of real 
> to anonymous addresses?
> this is exactly what i want
> 7) anything else you can tell us so we can give specific help.
> i want to store the mapping in postgres table or a disk file/
> i want to input the user email and choice via a form and then 
> take it to a func called anon(email_id, choice)
> if choice == yes:
>   geneate new anon email id correspondin to email_id
>   create or update a translation table to hold the link
>   return the anon email to create the new page with anon email id
>
> much like craiglist does
>
>
> */Bob Gailer <bgailer at alum.rpi.edu>/* wrote:
>
>     Luke Paireepinart wrote:
>     > anil maran wrote:
>     >
>     >> hi i m trying to anonymize emails
>     >>
>     > hi.
>     >
>     >> everytime someone enters
>     >> email at domain.com
>     >>
>     >> i want to generate
>     >>
>     >> cost-1234 at myweb.com and use this email in the web application
>     >>
>     >> I want to do this in python
>     >> can you please explain how to do this
>     >>
>     > Yes.
>     >
>     > Are you trying to anonymize their e-mail before it's sent to the
>     server
>     > or server-side?
>     > More info please.
>     > Are you using python cgi?
>     >
>     To amplify Luke's and others' questions - we need a lot more
>     information, and at this point in the process it seems painfully
>     slow to
>     extract it from you. If you want our help please tell us:
>     1) how much programming experience you have.
>     2) how new to Python are you.
>     3) why do you want to solve this problem in Python?
>     4) what can you apply from other languages you know (you refer to
>     Java
>     and C++) to this problem
>     5) have you written any Python code toward solving this problem?
>     6) do you need help in how to do string substitutions? how to
>     randomly
>     generate names? how to store persistently and retrieve mappings of
>     real
>     to anonymous addresses?
>     7) anything else you can tell us so we can give specific help.
>     > _______________________________________________
>     > Tutor maillist - Tutor at python.org
>     > http://mail.python.org/mailman/listinfo/tutor
>     >
>     >
>
>
>     -- 
>     Bob Gailer
>     510-978-4454
>
>
> ------------------------------------------------------------------------
> Yahoo! Music Unlimited - Access over 1 million songs. Try it free. 
> <http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=36035/*http://music.yahoo.com/unlimited/%20> 
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>   



More information about the Tutor mailing list