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

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

criado template principal

File size: 9.2 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    StringField('coding',
85        widget=StringWidget(
86            label='Coding',
87            label_msgid='PloneImapClient_label_coding',
88            description_msgid='PloneImapClient_help_coding',
89            i18n_domain='PloneImapClient',
90        )
91    ),
92
93    StringField('folderIN',
94        widget=StringWidget(
95            label='Folderin',
96            label_msgid='PloneImapClient_label_folderIN',
97            description_msgid='PloneImapClient_help_folderIN',
98            i18n_domain='PloneImapClient',
99        )
100    ),
101
102    StringField('folderOUT',
103        widget=StringWidget(
104            label='Folderout',
105            label_msgid='PloneImapClient_label_folderOUT',
106            description_msgid='PloneImapClient_help_folderOUT',
107            i18n_domain='PloneImapClient',
108        )
109    ),
110
111    StringField('folderTrash',
112        widget=StringWidget(
113            label='Foldertrash',
114            label_msgid='PloneImapClient_label_folderTrash',
115            description_msgid='PloneImapClient_help_folderTrash',
116            i18n_domain='PloneImapClient',
117        )
118    ),
119
120),
121)
122
123
124##code-section after-local-schema #fill in your manual code here
125##/code-section after-local-schema
126
127ImapClient_schema = BaseSchema + \
128    schema
129
130##code-section after-schema #fill in your manual code here
131##/code-section after-schema
132
133class ImapClient(UniqueObject,BaseContent):
134    """
135    <p>Tool do PloneImapClient</p>
136    """
137    security = ClassSecurityInfo()
138    __implements__ = (getattr(UniqueObject,'__implements__',()),) + (getattr(BaseContent,'__implements__',()),) + (IImapClient,)
139
140
141    # This name appears in the 'add' box
142    archetype_name             = 'PloneImapClient Tool'
143
144    meta_type                  = 'ImapClient'
145    portal_type                = 'ImapClient'
146    allowed_content_types      = []
147    filter_content_types       = 0
148    global_allow               = 0
149    allow_discussion           = 0
150    #content_icon               = 'ImapClient.gif'
151    immediate_view             = 'base_view'
152    default_view               = 'base_view'
153    suppl_views                = ()
154    typeDescription            = "PloneImapClient Tool"
155    typeDescMsgId              = 'description_edit_imapclient'
156    #toolicon                   = 'ImapClient.gif'
157
158    schema = ImapClient_schema
159
160    ##code-section class-header #fill in your manual code here
161    ##/code-section class-header
162
163
164    # tool-constructors have no id argument, the id is fixed
165    def __init__(self, id=None):
166        BaseContent.__init__(self,'portal_imapclient')
167       
168        ##code-section constructor-footer #fill in your manual code here
169        self.caches = []
170        self.conecoes = []
171        ##/code-section constructor-footer
172
173
174
175    #Methods
176
177    security.declarePublic('getConecaoIndex')
178    def getConecaoIndex(self,):
179        """
180       
181        """
182        print
183        print
184        print
185        print
186        print
187        print
188        print
189        print
190        mt = getToolByName(self,'portal_membership')
191        membro = mt.getAuthenticatedMember()
192
193        for i in xrange(len(self.conecoes)):
194            if self.conecoes[i][0] == str(membro):
195                try:
196                    self.conecoes[0][1].noop()
197                    return i
198                except:
199                    self.conecoes.__delitem__(i)
200                break
201       
202        # se no tiver uma conecao, retorna uma nova
203        print 'MEMBRO: ' + str(membro)
204
205        print 'SERVIDOR: ' + self.IMAPServer
206
207        c = imaplib.IMAP4(self.IMAPServer)
208        print 'CONECAO: ' + str(c)
209        print c.login(membro.getProperty('email_id',''), membro.getProperty('email_pass',''))
210        self.conecoes.append( [ str(membro), c ] )
211        print 'ADICIONOU NA LISTA'
212       
213        return len( self.conecoes ) - 1
214
215
216
217    security.declarePublic('getCacheIndex')
218    def getCacheIndex(self,):
219        """
220       
221        """
222        print 'PEGANDO A CACHE'
223        mt = getToolByName(self,'portal_membership')
224        membro = mt.getAuthenticatedMember()
225
226        for i in xrange(len(self.caches)):
227            if self.caches[i].getUser() == str(membro):
228                    return i
229       
230        # se no tiver uma conecao, retorna uma nova
231        cache = Cache(user=str(membro), _tool=self )
232        print 'CACHE: ' + str(cache)
233        self.caches.append( cache )
234       
235        return len( self.caches ) - 1
236
237
238
239    security.declarePublic('atualizarCache')
240    def atualizarCache(self,):
241        """
242       
243        """
244        #cache = self.getCache(user)
245        #cache.atualizar()
246        pass
247
248
249
250    security.declarePublic('getMail')
251    def getMail(self,folder,index):
252        """
253       
254        """
255       
256        pass
257
258
259
260    security.declarePublic('getHeaders')
261    def getHeaders(self,folder):
262        """
263            Pega os Headers da Cache e trata-os, possibilitando uso na ZMI       
264        """
265        print
266        print
267        print
268        print 'Pega os Headers da Cache e trata-os, possibilitando uso na ZMI'
269        print
270        print
271        print
272        print
273        i = self.getCacheIndex()
274        h= self.caches[i].get_headers(folder)
275        h2 = []
276        for j in h:
277            print '%50s $$$ %s'% ( str(j.get_from()), j.get_subject() )
278            print
279            h2.append(j.extract())
280        return h2
281        print
282        print
283        print
284        print
285
286
287
288    security.declarePublic('getFolders')
289    def getFolders(self,):
290        """
291       
292        """
293        i = self.getCacheIndex()
294        return self.caches[i].get_folders()
295
296
297
298    security.declarePublic('sentMail')
299    def sentMail(self,mail):
300        """
301       
302        """
303       
304        pass
305
306
307
308    security.declarePublic('delMail')
309    def delMail(self,folder,index):
310        """
311       
312        """
313       
314        pass
315
316
317
318    security.declarePublic('moveMail')
319    def moveMail(self,folder,index,destino):
320        """
321       
322        """
323       
324        pass
325
326
327
328    security.declarePublic('copyMail')
329    def copyMail(self,folder):
330        """
331       
332        """
333       
334        pass
335
336
337
338    security.declarePublic('newFolder')
339    def newFolder(self,pai,nome):
340        """
341       
342        """
343       
344        pass
345
346
347
348    security.declarePublic('delFolder')
349    def delFolder(self,nome):
350        """
351       
352        """
353       
354        pass
355
356
357def modify_fti(fti):
358    # hide unnecessary tabs (usability enhancement)
359    for a in fti['actions']:
360        if a['id'] in ['metadata']:
361            a['visible'] = 0
362    return fti
363
364registerType(ImapClient,PROJECTNAME)
365# end of class ImapClient
366
367##code-section module-footer #fill in your manual code here
368##/code-section module-footer
369
370
371
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.