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

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

criado template principal

File size: 5.1 KB
Linha 
1# File: Cache.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
25##code-section module-header #fill in your manual code here
26import Header
27##/code-section module-header
28
29
30
31
32class Cache:
33    ''' <p>cache das informacao do email de cada usuario</p>'''
34    __implements__ = ()
35
36    ##code-section class-header_Cache #fill in your manual code here
37    ##/code-section class-header_Cache
38
39
40    def __init__(self,*args,**kwargs):
41        self._init_attributes(*args,**kwargs)
42        self.atualizar()
43
44
45    def _init_attributes(self,*args,**kwargs):
46        #attributes
47        self._folders=None
48        self._headers=None
49        self._folderAtual=None
50        self._tool=None
51        self.user=None
52
53        # automatically set attributes where mutators exist
54        for key in kwargs.keys():
55            # camel case: variable -> setVariable
56            mutatorName = 'set'+key[0].upper()+key[1:]
57            mutator = getattr(self, mutatorName)
58            if mutator is not None and callable(mutator):
59                mutator(kwargs[key])
60
61
62    def maskAsRead(self,folder,index):
63        pass
64
65
66    def _atualizar_headers(self,folder):
67        self.set_folderAtual(folder)
68        self._headers = []
69       
70        index = self._tool.getConecaoIndex()
71        self._tool.conecoes[index][1].select(folder)
72       
73        typ, headers  = self._tool.conecoes[index][1].fetch('1:*','(UID FLAGS BODY.PEEK[HEADER.FIELDS (FROM TO CC IN-REPLY-TO SUBJECT DATE)])')
74       
75        if typ == 'No':
76            print 'deu erro!!!! em _atualizar_headers do folder ' + folder
77            print headers
78            return False
79
80        for i in xrange(0,len(headers),2):
81            info = headers[i][0] + headers[i+1]
82            header = Header.Header(info, headers[i][1])
83            self._headers.append(header)
84            print 'HEADER: ' + str(i/2)
85            print 'DATA: ' + header.get_date() + '   FROM: ' + str(header.get_from()[0]) + '   ASSUNTO: ' + str(header.get_subject())
86
87        return True
88       
89
90    def atualizar(self,):
91        index = self._tool.getConecaoIndex()
92        typ, lista = self._tool.conecoes[index][1].list()
93        folders = []
94        for i in lista:
95            if i.find(r'\Noselect') < 0:
96                if i[-1] == '"':
97                    name = i.split('"')[-2]
98                else:
99                    name = i.split(' ')[-1]
100                #
101                #
102                # PROBLEMA DE PERFORMANCE NO COMANDO STATUS
103                #
104                #
105                typ, [nmsg] = self._tool.conecoes[index][1].status(name,'(MESSAGES UNSEEN)')
106                # separa tudo
107                nmsg = nmsg.split('(')[-1].split(')')[0].split(' ')
108                nmsg[1] = int(nmsg[1])
109                nmsg[3] = int(nmsg[3])
110                # o numero de nao lidas deve ser menor ou igual ao total
111                if nmsg[1] < nmsg[3]:
112                    nlidas = nmsg[1]
113                    total = nmsg[3]
114                else:
115                    total = nmsg[1]
116                    nlidas = nmsg[3]
117                folders.append([name,nlidas,total])
118        self._folders = folders
119       
120        self._atualizar_headers('INBOX')
121
122
123
124
125    def set_headers(self,value):
126        self._headers=value
127
128
129    def set_folderAtual(self,value):
130        self._folderAtual=value
131
132
133    def get_headers(self, folder):
134        print
135        print '*********** PEGANDO HEADER ************'
136        print folder
137        if folder == self.get_folderAtual():
138            print 'folder igual'
139            print self._headers
140            return self._headers
141        else:
142            print 'folder diferente'
143            self._atualizar_headers(folder)
144            print self._headers
145            return self._headers
146
147
148    def get_tool(self):
149        return self._tool
150
151
152    def set_tool(self,value):
153        self._tool=value
154
155
156    def get_folders(self):
157        return self._folders
158
159
160    def getUser(self):
161        return self.user
162
163
164    def get_folderAtual(self):
165        return self._folderAtual
166
167
168    def setUser(self,value):
169        self.user=value
170
171
172    def set_folders(self,value):
173        self._folders=value
174
175
176##code-section module-footer #fill in your manual code here
177##/code-section module-footer
178
179
180
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.