source: publico/PloneImapClient/trunk/ImapClient.py @ 2532

Última Alteração nesse arquivo desde 2532 foi 2532, incluída por johnnysouza, 14 anos atrás

implementado mtodo Header.extract()

File size: 8.0 KB
Linha 
1# File: ImapClient.py
2#
3# Copyright (c) 2006 by Interlegis
4# Generator: ArchGenXML Version 1.4.0-RC2 svn/development
5#            http://plone.org/products/archgenxml
6#
7# GNU General Public Licence (GPL)
8#
9# This program is free software; you can redistribute it and/or modify it under
10# the terms of the GNU General Public License as published by the Free Software
11# Foundation; either version 2 of the License, or (at your option) any later
12# version.
13# This program is distributed in the hope that it will be useful, but WITHOUT
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16# details.
17# You should have received a copy of the GNU General Public License along with
18# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19# Place, Suite 330, Boston, MA  02111-1307  USA
20#
21__author__  = '''STC Interlegis <stc@interlegis.gov.br>'''
22__docformat__ = 'plaintext'
23
24
25from AccessControl import ClassSecurityInfo
26from Products.Archetypes.atapi import *
27from Products.PloneImapClient.interfaces.IImapClient import IImapClient
28
29
30from Products.Archetypes.SQLStorage import *
31# additional imports from tagged value 'import'
32import imaplib
33from Products.PloneImapClient.Cache import Cache
34
35from Products.PloneImapClient.config import *
36
37from Products.CMFCore.utils import UniqueObject
38
39   
40##code-section module-header #fill in your manual code here
41##/code-section module-header
42
43schema=Schema((
44    StringField('conecoes',
45        widget=StringWidget(
46            visible=0,
47            label='Conecoes',
48            label_msgid='PloneImapClient_label_conecoes',
49            description_msgid='PloneImapClient_help_conecoes',
50            i18n_domain='PloneImapClient',
51        )
52    ),
53
54    StringField('caches',
55        widget=StringWidget(
56            visible=0,
57            label='Caches',
58            label_msgid='PloneImapClient_label_caches',
59            description_msgid='PloneImapClient_help_caches',
60            i18n_domain='PloneImapClient',
61        )
62    ),
63
64    StringField('IMAPServer',
65        widget=StringWidget(
66            visible=1,
67            label='Imapserver',
68            label_msgid='PloneImapClient_label_IMAPServer',
69            description_msgid='PloneImapClient_help_IMAPServer',
70            i18n_domain='PloneImapClient',
71        )
72    ),
73
74    StringField('SMTPServer',
75        widget=StringWidget(
76            visible=1,
77            label='Smtpserver',
78            label_msgid='PloneImapClient_label_SMTPServer',
79            description_msgid='PloneImapClient_help_SMTPServer',
80            i18n_domain='PloneImapClient',
81        )
82    ),
83
84),
85)
86
87
88##code-section after-local-schema #fill in your manual code here
89##/code-section after-local-schema
90
91ImapClient_schema = BaseSchema + \
92    schema
93
94##code-section after-schema #fill in your manual code here
95##/code-section after-schema
96
97class ImapClient(UniqueObject,BaseContent):
98    """
99    <p>Tool do PloneImapClient</p>
100    """
101    security = ClassSecurityInfo()
102    __implements__ = (getattr(UniqueObject,'__implements__',()),) + (getattr(BaseContent,'__implements__',()),) + (IImapClient,)
103
104
105    # This name appears in the 'add' box
106    archetype_name             = 'PloneImapClient Tool'
107
108    meta_type                  = 'ImapClient'
109    portal_type                = 'ImapClient'
110    allowed_content_types      = []
111    filter_content_types       = 0
112    global_allow               = 0
113    allow_discussion           = 0
114    #content_icon               = 'ImapClient.gif'
115    immediate_view             = 'base_view'
116    default_view               = 'base_view'
117    suppl_views                = ()
118    typeDescription            = "PloneImapClient Tool"
119    typeDescMsgId              = 'description_edit_imapclient'
120    #toolicon                   = 'ImapClient.gif'
121
122    schema = ImapClient_schema
123
124    ##code-section class-header #fill in your manual code here
125    ##/code-section class-header
126
127
128    # tool-constructors have no id argument, the id is fixed
129    def __init__(self, id=None):
130        BaseContent.__init__(self,'portal_imapclient')
131       
132        ##code-section constructor-footer #fill in your manual code here
133        self.caches = []
134        self.conecoes = []
135        ##/code-section constructor-footer
136
137
138
139    #Methods
140
141    security.declarePublic('getConecaoIndex')
142    def getConecaoIndex(self,):
143        """
144       
145        """
146        print
147        print
148        print
149        print
150        print
151        print
152        print
153        print
154        mt = getToolByName(self,'portal_membership')
155        membro = mt.getAuthenticatedMember()
156
157        for i in xrange(len(self.conecoes)):
158            if self.conecoes[i][0] == str(membro):
159                try:
160                    self.conecoes[0][1].noop()
161                    return i
162                except:
163                    self.conecoes.__delitem__(i)
164                break
165       
166        # se no tiver uma conecao, retorna uma nova
167        print 'MEMBRO: ' + str(membro)
168
169        print 'SERVIDOR: ' + self.IMAPServer
170
171        c = imaplib.IMAP4(self.IMAPServer)
172        print 'CONECAO: ' + str(c)
173        print c.login(membro.getProperty('email_id',''), membro.getProperty('email_pass',''))
174        self.conecoes.append( [ str(membro), c ] )
175        print 'ADICIONOU NA LISTA'
176       
177        return len( self.conecoes ) - 1
178
179
180
181    security.declarePublic('getCacheIndex')
182    def getCacheIndex(self,):
183        """
184       
185        """
186        mt = getToolByName(self,'portal_membership')
187        membro = mt.getAuthenticatedMember()
188
189        for i in xrange(len(self.caches)):
190            if self.caches[i].getUser() == str(membro):
191                    return i
192       
193        # se no tiver uma conecao, retorna uma nova
194        cache = Cache(user=str(membro), _tool=self )
195        print 'CACHE: ' + str(cache)
196        self.caches.append( cache )
197       
198        return len( self.caches ) - 1
199
200
201
202    security.declarePublic('atualizarCache')
203    def atualizarCache(self,):
204        """
205       
206        """
207        #cache = self.getCache(user)
208        #cache.atualizar()
209        pass
210
211
212
213    security.declarePublic('getMail')
214    def getMail(self,folder,index):
215        """
216       
217        """
218       
219        pass
220
221
222
223    security.declarePublic('getHeaders')
224    def getHeaders(self,folder):
225        """
226            Pega os Headers da Cache e trata-os, possibilitando uso na ZMI       
227        """
228        print
229        print
230        print
231        print
232        print
233        print
234        print
235        print
236        i = self.getCacheIndex()
237        h= self.caches[i].get_headers(folder)
238        h2 = []
239        for j in h:
240            print '%50s $$$ %s'% ( str(j.get_from()), j.get_subject() )
241            print
242            h2.append(j.extract())
243        return h2
244        print
245        print
246        print
247        print
248
249
250
251    security.declarePublic('getFolders')
252    def getFolders(self,):
253        """
254       
255        """
256        i = self.getCacheIndex()
257        return self.caches[i].get_folders()
258
259
260    security.declarePublic('sentMail')
261    def sentMail(self,mail):
262        """
263       
264        """
265       
266        pass
267
268
269
270    security.declarePublic('delMail')
271    def delMail(self,folder,index):
272        """
273       
274        """
275       
276        pass
277
278
279
280    security.declarePublic('moveMail')
281    def moveMail(self,folder,index,destino):
282        """
283       
284        """
285       
286        pass
287
288
289
290    security.declarePublic('copyMail')
291    def copyMail(self,folder):
292        """
293       
294        """
295       
296        pass
297
298
299
300    security.declarePublic('newFolder')
301    def newFolder(self,pai,nome):
302        """
303       
304        """
305       
306        pass
307
308
309
310    security.declarePublic('delFolder')
311    def delFolder(self,nome):
312        """
313       
314        """
315       
316        pass
317
318
319def modify_fti(fti):
320    # hide unnecessary tabs (usability enhancement)
321    for a in fti['actions']:
322        if a['id'] in ['metadata']:
323            a['visible'] = 0
324    return fti
325
326registerType(ImapClient,PROJECTNAME)
327# end of class ImapClient
328
329##code-section module-footer #fill in your manual code here
330##/code-section module-footer
331
332
333
Note: Veja TracBrowser para ajuda no uso do navegador do trac.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.