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

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

implementado mtodo de atualizacao de headers

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