try:
  import email,mimetypes

  def decode_email(data,dir):
      msg=email.message_from_string(data)
      files=[]
      counter=1
      for part in msg.walk():
        if part.get_content_maintype()=='multipart':
          continue
        filename='part-%06d' % (counter)
        counter=counter+1
        fp=open(os.path.join(dir,filename), 'wb')
        fp.write(part.get_payload(decode=1))
        fp.close()
        files.append(filename)
      return files
except ImportError:
  def decode_email(data,dir):
      raise 'decode_email', 'You need email library from python2!'
