Skip navigation

Monthly Archives: August 2009

import email, getpass, imaplib, os

detach_dir = '.'

### directory where to save attachments (default: current)

m = imaplib.IMAP4_SSL('imap.gmail.com', 993)
m.login('username@gmail.com','password')
keywordsSearch = 'bananas oranges'
searchString = "(ALL SUBJECT '%s')" % keywordsSearch

### m.search(None, "(ALL SUBJECT 'bananas oranges')")
resp, items = m.search(None, searchString)
items = items[0].split()
for emailid in items:
    resp, data = m.fetch(emailid, "(RFC822)")
    email_body = data[0][1]
    mail = email.message_from_string(email_body)
    if mail.get_content_maintype() != 'multipart':
        continue
    print "["+mail["From"]+"] :" + mail["Subject"]
    for part in mail.walk():
        if part.get_content_maintype() == 'multipart':
            continue
        if part.get('Content-Disposition') is None:
            continue
        filename = part.get_filename()
        counter = 1
        if not filename:
            filename = 'part-%03d%s' % (counter, 'bin')
            counter += 1
        att_path = os.path.join(detach_dir, filename)
        if not os.path.isfile(att_path) :
            fp = open(att_path, 'wb')
            fp.write(part.get_payload(decode=True))
            fp.close()

There is an issue with Drupal 6 menu router rebuild which causes Drupal to time out with 404 pages or internal 500.

The following fix worked for me:

Install Drupal Tweaks, increase php memory, and mysql recommendations etc

http://drupal.org/project/drupal_tweaks

Download the following patches:

http://drupal.org/node/251792#comment-1831346


http://drupal.org/node/317775#comment-1491208

From command line copy patches to your root drupal directory.

cd to your root drupal directory and then apply the patches. Each time you will be asked where the file is for the patch and the actual path to the files to be patched will be provided in the command line. Just copy and paste each file path as presented into the prompt.


cp *.patch /home/drupal_directory/
cd /home/drupal_directory/
patch < no-router-blob-317775-56-D6.patch
patch < lock-251792-163-D6.patch

|--- includes/bootstrap.inc (revision 7577)
|+++ includes/bootstrap.inc (working copy)
--------------------------
File to patch: includes/bootstrap.inc

So in the above text you can see it gives you the path ‘includes/bootstrap.inc’. Just copy and paste that to where it says ‘File to patch:’. For each file it will provide you the correct path to the file assuming you are in the drupal root directory.

The final thing to do is to cp the lock.inc file which is created to includes/