File: GoogleHandler.py

package info (click to toggle)
mbot 0.3-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 212 kB
  • ctags: 119
  • sloc: python: 595; makefile: 102; php: 98; sql: 59
file content (48 lines) | stat: -rw-r--r-- 1,422 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python

# mbot - a mail handling robot
#
# Author:  Dimitri Fontaine <dim@tapoueh.org>
#
# This code is licensed under the GPL.
# Get yourself a version here : http://www.gnu.org/copyleft/gpl.html

# $Id: GoogleHandler.py,v 1.12 2003/12/22 11:04:47 dim Exp $

import MailHandler
import string, urllib, httplib, mimetools
import ConfigParser

from MailHandler import MailHandler

class GoogleHandler(MailHandler):
    "Handle getting url given in mail"
    
    def read_conf(self, ConfObj):
        ''' Getting config options for this handler '''
        self.log.notice("[GoogleHandler]: read_conf")
        MailHandler.read_conf(self, ConfObj,
	                      ['host', 'base_url'])

    def handle(self, body):
        """ The body may contain one url per line """
        result = []

        self.log.notice("[GoogleHandler]")
        for line in body.split('\n'):
            if line != '' and line is not None:
                url = self.base_url + urllib.quote(line)
                self.log.debug("[GoogleHandler]: url='%s'" \
                                   % url)
                conn = httplib.HTTPConnection(self.host)
                conn.request("GET", url)
                r = conn.getresponse()

                type = r.msg.gettype()
                data = r.read()

                conn.close()
                
                result.append((type, data))

        return result