1
- # pylint: disable=too-many-instance-attributes,attribute-defined-outside-init
2
1
"""
3
- account.py
4
- ==========
5
-
6
2
Account related functions.
7
3
8
4
"""
9
5
10
- from __future__ import absolute_import
11
-
12
6
import inspect
13
7
import re
14
8
import sys
15
9
import time
16
10
17
- from PyQt4 import QtGui
18
-
19
11
import queues
20
12
from addresses import decodeAddress
21
13
from bmconfigparser import BMConfigParser
22
14
from helper_ackPayload import genAckPayload
23
15
from helper_sql import sqlQuery , sqlExecute
24
- from .foldertree import AccountMixin
25
- from .utils import str_broadcast_subscribers
16
+ from foldertree import AccountMixin
17
+ from utils import str_broadcast_subscribers
18
+ from tr import _translate
26
19
27
20
28
21
def getSortedAccounts ():
29
- """Get a sorted list of configSections"""
30
-
22
+ """Get a sorted list of address config sections"""
31
23
configSections = BMConfigParser ().addresses ()
32
24
configSections .sort (
33
25
cmp = lambda x , y : cmp (
34
- unicode (
35
- BMConfigParser ().get (
36
- x ,
37
- 'label' ),
38
- 'utf-8' ).lower (),
39
- unicode (
40
- BMConfigParser ().get (
41
- y ,
42
- 'label' ),
43
- 'utf-8' ).lower ()))
26
+ unicode (BMConfigParser ().get (x , 'label' ), 'utf-8' ).lower (),
27
+ unicode (BMConfigParser ().get (y , 'label' ), 'utf-8' ).lower ())
28
+ )
44
29
return configSections
45
30
46
31
@@ -94,7 +79,8 @@ def accountClass(address):
94
79
return subscription
95
80
try :
96
81
gateway = BMConfigParser ().get (address , "gateway" )
97
- for _ , cls in inspect .getmembers (sys .modules [__name__ ], inspect .isclass ):
82
+ for _ , cls in inspect .getmembers (
83
+ sys .modules [__name__ ], inspect .isclass ):
98
84
if issubclass (cls , GatewayAccount ) and cls .gatewayName == gateway :
99
85
return cls (address )
100
86
# general gateway
@@ -105,7 +91,7 @@ def accountClass(address):
105
91
return BMAccount (address )
106
92
107
93
108
- class AccountColor (AccountMixin ): # pylint: disable=too-few-public-methods
94
+ class AccountColor (AccountMixin ):
109
95
"""Set the type of account"""
110
96
111
97
def __init__ (self , address , address_type = None ):
@@ -127,12 +113,35 @@ def __init__(self, address, address_type=None):
127
113
self .type = address_type
128
114
129
115
130
- class BMAccount (object ):
131
- """Encapsulate a Bitmessage account """
132
-
116
+ class NoAccount (object ):
117
+ """Minimal account like object (All accounts) """
118
+ # pylint: disable=too-many-instance-attributes
133
119
def __init__ (self , address = None ):
134
120
self .address = address
135
121
self .type = AccountMixin .NORMAL
122
+ self .toAddress = self .fromAddress = ''
123
+ self .subject = self .message = ''
124
+ self .fromLabel = self .toLabel = ''
125
+
126
+ def getLabel (self , address = None ):
127
+ """Get a label for this bitmessage account"""
128
+ return address or self .address
129
+
130
+ def parseMessage (self , toAddress , fromAddress , subject , message ):
131
+ """Set metadata and address labels on self"""
132
+ self .toAddress = toAddress
133
+ self .fromAddress = fromAddress
134
+ self .subject = subject
135
+ self .message = message
136
+ self .fromLabel = self .getLabel (fromAddress )
137
+ self .toLabel = self .getLabel (toAddress )
138
+
139
+
140
+ class BMAccount (NoAccount ):
141
+ """Encapsulate a Bitmessage account"""
142
+
143
+ def __init__ (self , address = None ):
144
+ super (BMAccount , self ).__init__ (address )
136
145
if BMConfigParser ().has_section (address ):
137
146
if BMConfigParser ().safeGetBoolean (self .address , 'chan' ):
138
147
self .type = AccountMixin .CHAN
@@ -148,8 +157,7 @@ def __init__(self, address=None):
148
157
149
158
def getLabel (self , address = None ):
150
159
"""Get a label for this bitmessage account"""
151
- if address is None :
152
- address = self .address
160
+ address = super (BMAccount , self ).getLabel (address )
153
161
label = BMConfigParser ().safeGet (address , 'label' , address )
154
162
queryreturn = sqlQuery (
155
163
'''select label from addressbook where address=?''' , address )
@@ -162,33 +170,7 @@ def getLabel(self, address=None):
162
170
if queryreturn != []:
163
171
for row in queryreturn :
164
172
label , = row
165
- return label
166
-
167
- def parseMessage (self , toAddress , fromAddress , subject , message ):
168
- """Set metadata and address labels on self"""
169
-
170
- self .toAddress = toAddress
171
- self .fromAddress = fromAddress
172
- if isinstance (subject , unicode ):
173
- self .subject = str (subject )
174
- else :
175
- self .subject = subject
176
- self .message = message
177
- self .fromLabel = self .getLabel (fromAddress )
178
- self .toLabel = self .getLabel (toAddress )
179
-
180
-
181
- class NoAccount (BMAccount ):
182
- """Override the __init__ method on a BMAccount"""
183
-
184
- def __init__ (self , address = None ): # pylint: disable=super-init-not-called
185
- self .address = address
186
- self .type = AccountMixin .NORMAL
187
-
188
- def getLabel (self , address = None ):
189
- if address is None :
190
- address = self .address
191
- return address
173
+ return unicode (label , 'utf-8' )
192
174
193
175
194
176
class SubscriptionAccount (BMAccount ):
@@ -208,15 +190,11 @@ class GatewayAccount(BMAccount):
208
190
ALL_OK = 0
209
191
REGISTRATION_DENIED = 1
210
192
211
- def __init__ (self , address ):
212
- super (GatewayAccount , self ).__init__ (address )
213
-
214
193
def send (self ):
215
- """Override the send method for gateway accounts"""
216
-
217
- # pylint: disable=unused-variable
218
- status , addressVersionNumber , streamNumber , ripe = decodeAddress (self .toAddress )
219
- stealthLevel = BMConfigParser ().safeGetInt ('bitmessagesettings' , 'ackstealthlevel' )
194
+ """The send method for gateway accounts"""
195
+ streamNumber , ripe = decodeAddress (self .toAddress )[2 :]
196
+ stealthLevel = BMConfigParser ().safeGetInt (
197
+ 'bitmessagesettings' , 'ackstealthlevel' )
220
198
ackdata = genAckPayload (streamNumber , stealthLevel )
221
199
sqlExecute (
222
200
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''' ,
@@ -289,10 +267,9 @@ def status(self):
289
267
290
268
def settings (self ):
291
269
"""settings specific to a MailchuckAccount"""
292
-
293
270
self .toAddress = self .registrationAddress
294
271
self .subject = "config"
295
- self .message = QtGui . QApplication . translate (
272
+ self .message = _translate (
296
273
"Mailchuck" ,
297
274
"""# You can use this to configure your email gateway account
298
275
# Uncomment the setting you want to use
@@ -338,8 +315,9 @@ def settings(self):
338
315
339
316
def parseMessage (self , toAddress , fromAddress , subject , message ):
340
317
"""parseMessage specific to a MailchuckAccount"""
341
-
342
- super (MailchuckAccount , self ).parseMessage (toAddress , fromAddress , subject , message )
318
+ super (MailchuckAccount , self ).parseMessage (
319
+ toAddress , fromAddress , subject , message
320
+ )
343
321
if fromAddress == self .relayAddress :
344
322
matches = self .regExpIncoming .search (subject )
345
323
if matches is not None :
@@ -360,6 +338,7 @@ def parseMessage(self, toAddress, fromAddress, subject, message):
360
338
self .toLabel = matches .group (1 )
361
339
self .toAddress = matches .group (1 )
362
340
self .feedback = self .ALL_OK
363
- if fromAddress == self .registrationAddress and self .subject == "Registration Request Denied" :
341
+ if fromAddress == self .registrationAddress \
342
+ and self .subject == "Registration Request Denied" :
364
343
self .feedback = self .REGISTRATION_DENIED
365
344
return self .feedback
0 commit comments