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 |
---|
26 | import Header |
---|
27 | ##/code-section module-header |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | class 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 | def set_headers(self,value): |
---|
124 | self._headers=value |
---|
125 | |
---|
126 | |
---|
127 | def set_folderAtual(self,value): |
---|
128 | self._folderAtual=value |
---|
129 | |
---|
130 | def get_tool(self): |
---|
131 | return self._tool |
---|
132 | |
---|
133 | |
---|
134 | def set_tool(self,value): |
---|
135 | self._tool=value |
---|
136 | |
---|
137 | |
---|
138 | def get_folders(self): |
---|
139 | return self._folders |
---|
140 | |
---|
141 | |
---|
142 | def getUser(self): |
---|
143 | return self.user |
---|
144 | |
---|
145 | |
---|
146 | def get_folderAtual(self): |
---|
147 | return self._folderAtual |
---|
148 | |
---|
149 | |
---|
150 | def setUser(self,value): |
---|
151 | self.user=value |
---|
152 | |
---|
153 | |
---|
154 | def get_headers(self, folder): |
---|
155 | print |
---|
156 | print '*********** PEGANDO HEADER ************' |
---|
157 | print folder |
---|
158 | if folder == self.get_folderAtual(): |
---|
159 | print 'folder igual' |
---|
160 | print self._headers |
---|
161 | return self._headers |
---|
162 | else: |
---|
163 | print 'folder diferente' |
---|
164 | self._atualizar_headers(folder) |
---|
165 | print self._headers |
---|
166 | return self._headers |
---|
167 | |
---|
168 | |
---|
169 | def set_folders(self,value): |
---|
170 | self._folders=value |
---|
171 | |
---|
172 | |
---|
173 | ##code-section module-footer #fill in your manual code here |
---|
174 | ##/code-section module-footer |
---|
175 | |
---|
176 | |
---|
177 | |
---|