Document Actions

Content Acquisition through mail in Plone

by shalini last modified 2007-02-12 15:45
Content Acquisition through mail

-----------------------------------------------------------------------------------------------------------------------------
Description:

To create plone content whether its Document,Event....etc using mail messages by directly accessing the mail account from a plone site.

As all created content will be placed in a particular folder for a  cleaner approach, So it is advisable to  create a folder with id "test_folder"(It can be any name but should be unique ) where all the created  content can be placed.

----------------------------------------------------------------------------------------------------------------------------
Dependencies:

To run this script libgmail should be installed or can install from
 
http://sourceforge.net/project/showfiles.php?group_id=113492&package_id=122807&release_id=437997

libgmail ---- A library to provide access to  Gmail via  python.

Steps to install libgmail.
1. tar zxvf libgmail-0.1.5.1.tar.gz
2. cd libgmail-0.1.5.1
3. python setup.py install

----------------------------------------------------------------------------------------------------------------------------
Source:

#On the file system in $ZOPE/Extension
#create a file called mkcontent.py


from Products.CMFCore.utils import getToolByName
import libgmail
import sys
from getpass import getpass


def mkcont(self):


        ga = libgmail.GmailAccount("<Enter your Gmail Id>","<your password>")

    #---------It logs in to the GamilAccount---------------------------------------------------

        ga.login()

    #------------- Reads messages from 'Inbox'-------------------------------------------------

        folder = ga.getMessagesByFolder('inbox')
   
    #------Get a reference to portal-----------------------------------------------------------

        urltool = getToolByName(self, "portal_url")

    #----Get a reference to catalog tool------------------------------------------------------

        catalogtool = getToolByName(self, "portal_catalog")

        portal = urltool.getPortalObject()

    #----------- Get a reference to a folder in portal whose id is  test_folder----------------
   
        folder1 = getattr(portal, "test_folder")

        for thread in folder:
          for msg in thread:
                title= msg.subject
                id=thread.id
                sub=msg.source
                doc = folder1.invokeFactory("Document", id)
       
        #-------------- Create document in folder1 ----------------------------------------
                document = getattr(folder1, id)
                document.editMetadata(title=title,
                                      description="This is the description of a test document",
                                      subject="")
                document.edit(text_format="html",
                                text=sub)


    #--------------------Reindex all objects found inside self---------------------------------
        catalogtool.refreshCatalog(self)

----------------------------------------------------------------------------------------------------------------------------

Implementation


Now in Zope Managemet Interface.

create an External method id = createcontent, title = create content, module = mkcontent.py, function=mkcont

Save it & test it!!!!

 

 

 
Contact: OneWorld South Asia, C-5 Qutab Institutional Area, New Delhi 110016, Tel: 91-11-4168 9000, Fax: 91-11-4168 9001
Email: webmaster at ekduniya dot net