bugfix upload

This commit is contained in:
a-Sansara 2012-09-29 20:38:04 +02:00
parent 34b8ef3aab
commit 46bb274636
6 changed files with 155 additions and 84 deletions

View File

@ -3,7 +3,7 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # #
# software : ImpraStorage <http://imprastorage.sourceforge.net/> # # software : ImpraStorage <http://imprastorage.sourceforge.net/> #
# version : 0.4 # # version : 0.6 #
# date : 2012 # # date : 2012 #
# licence : GPLv3.0 <http://www.gnu.org/licenses/> # # licence : GPLv3.0 <http://www.gnu.org/licenses/> #
# author : a-Sansara <http://www.a-sansara.net/> # # author : a-Sansara <http://www.a-sansara.net/> #
@ -41,7 +41,7 @@ LINE_SEP_LEN = 120
LINE_SEP_CHAR = '' LINE_SEP_CHAR = ''
if not Clz.isUnix : LINE_SEP_CHAR = '-' if not Clz.isUnix : LINE_SEP_CHAR = '-'
APP_TITLE = 'ImpraStorage' APP_TITLE = 'ImpraStorage'
APP_VERSION = '0.5' APP_VERSION = '0.6'
APP_AUTHOR = 'a-Sansara' APP_AUTHOR = 'a-Sansara'
APP_COPY = 'pluie.org' APP_COPY = 'pluie.org'
APP_LICENSE = 'GNU GPLv3' APP_LICENSE = 'GNU GPLv3'
@ -118,13 +118,14 @@ class Cli:
gpConf.add_option('-V', '--view' , help='view configuration' , action='store' ) gpConf.add_option('-V', '--view' , help='view configuration' , action='store' )
gpConf.add_option('-L', '--load' , help='load configuration' , action='store' ) gpConf.add_option('-L', '--load' , help='load configuration' , action='store' )
gpConf.add_option('-S', '--save' , help='save configuration' , action='store' ) gpConf.add_option('-S', '--save' , help='save configuration' , action='store' )
gpConf.add_option('-C', '--check' , help='check configuration' , action='store' )
gpConf.add_option('-H', '--set-host' , help='set imap host server' , action='store', metavar='HOST ') gpConf.add_option('-H', '--set-host' , help='set imap host server' , action='store', metavar='HOST ')
gpConf.add_option('-U', '--set-user' , help='set imap user login' , action='store', metavar='USER ') gpConf.add_option('-U', '--set-user' , help='set imap user login' , action='store', metavar='USER ')
gpConf.add_option('-X', '--set-pass' , help='set imap user password' , action='store', metavar='PASS ') gpConf.add_option('-X', '--set-pass' , help='set imap user password' , action='store', metavar='PASS ')
gpConf.add_option('-P', '--set-port' , help='set imap port' , action='store', metavar='PORT ') gpConf.add_option('-P', '--set-port' , help='set imap port' , action='store', metavar='PORT ')
gpConf.add_option('-N', '--set-name' , help='set user name' , action='store', metavar='NAME ') gpConf.add_option('-N', '--set-name' , help='set user name' , action='store', metavar='NAME ')
gpConf.add_option('-B', '--set-boxn' , help='set boxName on imap server (default:[%default])' , action='store', metavar='BOXNAME ') gpConf.add_option('-B', '--set-boxname' , help='set boxName on imap server (default:[%default])' , action='store', metavar='BOXNAME ')
gpConf.add_option('-K', '--gen-keys' , help='generate new key' , action='store_true', default=False) gpConf.add_option('-K', '--gen-key' , help='generate new key' , action='store_true', default=False)
parser.add_option_group(gpConf) parser.add_option_group(gpConf)
@ -154,7 +155,7 @@ class Cli:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ conf CMD ~~ # ~~ conf CMD ~~
if a[0] == 'conf' : if a[0] == 'conf' :
self.print_header()
if o.load is not None or o.view is not None or o.save is not None : if o.load is not None or o.view is not None or o.save is not None :
if o.view is not None : if o.view is not None :
@ -170,22 +171,28 @@ class Cli:
if o.load : self.load_profile(o) if o.load : self.load_profile(o)
elif o.view : self.ini.print(o.active_profile) elif o.view :
if o.view == 'all' :
sections = self.ini.getSections()
if len(sections) > 0:
Clz.print(' '+','.join(sections), Clz.fgB3)
else : Clz.print(' no profiles', Clz.fgB1)
else: self.ini.print(o.view)
elif o.save : elif o.save :
if not o.set_host and not o.set_user and not o.set_pass and not o.set_port and not o.set_boxn and not o.set_name and not o.gen_keys: if not o.set_host and not o.set_user and not o.set_pass and not o.set_port and not o.set_boxname and not o.set_name and not o.gen_key:
parser.error(' no options specified') parser.error(' no options specified')
else : else :
if o.set_port and not util.represents_int(o.set_port): if o.set_port and not util.represents_int(o.set_port):
parser.error(' port must be a number') parser.error(' port must be a number')
sys.exit(1) sys.exit(1)
if o.set_boxn: self.ini.set('box' , o.set_boxn,o.active_profile+'.imap') if o.set_boxname: self.ini.set('box' , o.set_boxname,o.active_profile+'.imap')
if o.set_host: self.ini.set('host', o.set_host,o.active_profile+'.imap') if o.set_host: self.ini.set('host', o.set_host,o.active_profile+'.imap')
if o.set_user: self.ini.set('user', o.set_user,o.active_profile+'.imap') if o.set_user: self.ini.set('user', o.set_user,o.active_profile+'.imap')
if o.set_pass: self.ini.set('pass', o.set_pass,o.active_profile+'.imap') if o.set_pass: self.ini.set('pass', o.set_pass,o.active_profile+'.imap')
if o.set_port: self.ini.set('port', o.set_port,o.active_profile+'.imap') if o.set_port: self.ini.set('port', o.set_port,o.active_profile+'.imap')
if o.set_name: self.ini.set('name', o.set_name,o.active_profile+'.infos') if o.set_name: self.ini.set('name', o.set_name,o.active_profile+'.infos')
if o.gen_keys: if o.gen_key:
kg = crypt.KeyGen(256) kg = crypt.KeyGen(256)
self.ini.set('key' ,kg.key,o.active_profile+'.keys') self.ini.set('key' ,kg.key,o.active_profile+'.keys')
self.ini.set('mark',kg.mark,o.active_profile+'.keys') self.ini.set('mark',kg.mark,o.active_profile+'.keys')
@ -194,6 +201,9 @@ class Cli:
self.ini.set('profile', o.active_profile) self.ini.set('profile', o.active_profile)
self.ini.write() self.ini.write()
self.ini.print(o.active_profile) self.ini.print(o.active_profile)
elif o.check :
self.check_profile(o.check, True)
else : else :
self.print_usage('') self.print_usage('')
@ -205,6 +215,7 @@ class Cli:
if self.check_profile(o.active_profile): if self.check_profile(o.active_profile):
self.print_header()
conf = core.ImpraConf(self.ini,o.active_profile) conf = core.ImpraConf(self.ini,o.active_profile)
impst = None impst = None
try: try:
@ -273,6 +284,7 @@ class Cli:
elif a[0] == 'add': elif a[0] == 'add':
if not len(a)>1 : self.error_cmd('`'+a[0]+' need at least one argument',parser) if not len(a)>1 : self.error_cmd('`'+a[0]+' need at least one argument',parser)
vfile = a[1] vfile = a[1]
if util.file_exists(vfile) : if util.file_exists(vfile) :
if not len(a)>2 : if not len(a)>2 :
@ -291,8 +303,8 @@ class Cli:
elif a[0] == 'get': elif a[0] == 'get':
if not len(a)>1 : self.error_cmd('`'+a[0]+' need one argument',parser) if not len(a)>1 : self.error_cmd('`'+a[0]+' need one argument',parser)
vid = a[1]
vid = a[1]
ids = [] ids = []
for sid in vid.split(',') : for sid in vid.split(',') :
seq = sid.split('-') seq = sid.split('-')
@ -374,6 +386,13 @@ class Cli:
elif a[0] == 'remove': elif a[0] == 'remove':
if not len(a)>1 : self.error_cmd('`'+a[0]+' need one argument',parser) if not len(a)>1 : self.error_cmd('`'+a[0]+' need one argument',parser)
if not util.represents_int(a[1]):
print('\n ',end='')
Clz.print(' == `' , Clz.bg1+Clz.fgB7, False)
Clz.print(a[1] , Clz.bg1+Clz.fgB3, False)
Clz.print('` is not a valid id == ', Clz.bg1+Clz.fgB7)
print()
sys.exit(1)
vid = a[1] vid = a[1]
key = impst.index.getById(vid) key = impst.index.getById(vid)
if key !=None : if key !=None :
@ -385,7 +404,7 @@ class Cli:
else: else:
print('\n ',end='') print('\n ',end='')
Clz.print(' == `' , Clz.bg1+Clz.fgB7, False) Clz.print(' == `' , Clz.bg1+Clz.fgB7, False)
Clz.print(str(o.remove) , Clz.bg1+Clz.fgB3, False) Clz.print(a[1] , Clz.bg1+Clz.fgB3, False)
Clz.print('` is not a valid id == ', Clz.bg1+Clz.fgB7) Clz.print('` is not a valid id == ', Clz.bg1+Clz.fgB7)
print() print()
@ -398,9 +417,38 @@ class Cli:
parser.error(msg) parser.error(msg)
sys.exit(1) sys.exit(1)
def check_profile(self,profile): def check_profile(self,profile, activeCheck=False):
"""""" """"""
return self.ini.hasSection(profile+'.keys') and self.ini.has('host',profile+'.imap') and self.ini.has('user',profile+'.imap') and self.ini.has('pass',profile+'.imap') and self.ini.has('port',profile+'.imap') c = self.ini.hasSection(profile+'.keys') and self.ini.has('host',profile+'.imap') and self.ini.has('user',profile+'.imap') and self.ini.has('pass',profile+'.imap') and self.ini.has('port',profile+'.imap')
if activeCheck :
if c :
Clz.print(' '+profile+' is ok', Clz.fgB2)
Clz.print(' testing...', Clz.fgB3)
conf = core.ImpraConf(self.ini,profile)
impst = None
try:
impst = core.ImpraStorage(conf)
Clz.print(' done...', Clz.fgB2)
except crypt.BadKeyException as e :
pass
else :
Clz.print(' '+profile+' incomplete', Clz.fgB1)
Clz.print(' need :', Clz.fgB1)
if not self.ini.hasSection(profile+'.keys'):
Clz.print(' key (conf -S "'+profile+'" -K)', Clz.fgB1)
if not self.ini.has('host',profile+'.imap'):
Clz.print(' imap host (conf -S "'+profile+'" -H hostName)', Clz.fgB1)
if not self.ini.has('user',profile+'.imap'):
Clz.print(' imap user (conf -S "'+profile+'" -U userName)', Clz.fgB1)
if not self.ini.has('pass',profile+'.imap'):
Clz.print(' imap password (conf -S "'+profile+'" -X password)', Clz.fgB1)
if not self.ini.has('port',profile+'.imap'):
Clz.print(' imap port (conf -S "'+profile+'" -P port)', Clz.fgB1)
if not self.ini.has('name',profile+'.infos'):
if c :
Clz.print(' think to add your userName :',Clz.bgB3)
Clz.print(' userName (conf -S "'+profile+'" -N yourName)', Clz.fgB3)
return c
def print_header(self): def print_header(self):
printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN) printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
@ -507,10 +555,7 @@ class Cli:
Clz.print('profile', Clz.fgb1, False) Clz.print('profile', Clz.fgb1, False)
Clz.print('} ', Clz.fgB1, False) Clz.print('} ', Clz.fgB1, False)
Clz.print('[', Clz.fgB3, False) Clz.print('[', Clz.fgB3, False)
Clz.print(' -K ', Clz.fgB3, False) Clz.print(' -K', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False)
Clz.print('length', Clz.fgB1, False)
Clz.print('}', Clz.fgB1, False)
Clz.print(', -H ', Clz.fgB3, False) Clz.print(', -H ', Clz.fgB3, False)
Clz.print('{', Clz.fgB1, False) Clz.print('{', Clz.fgB1, False)
Clz.print('host', Clz.fgB1, False) Clz.print('host', Clz.fgB1, False)
@ -588,7 +633,7 @@ class Cli:
Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1, False) Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --view'.ljust(18,' ') , Clz.fgB3, False) Clz.print(', --view'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1) Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'view the specified profile (or current)' , Clz.fgB7) Clz.print(' '*50+'view the specified profile (or * for all available)' , Clz.fgB7)
Clz.print(' '*4+'-S ' , Clz.fgB3, False) Clz.print(' '*4+'-S ' , Clz.fgB3, False)
Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1, False) Clz.print('PROFILE'.ljust(10,' ') , Clz.fgB1, False)
@ -605,10 +650,10 @@ class Cli:
Clz.print(' '*50+'set imprastorage username' , Clz.fgB7) Clz.print(' '*50+'set imprastorage username' , Clz.fgB7)
Clz.print(' '*4+'-K ' , Clz.fgB3, False) Clz.print(' '*4+'-K ' , Clz.fgB3, False)
Clz.print('LENGTH'.ljust(10,' ') , Clz.fgB1, False) Clz.print(''.ljust(10,' ') , Clz.fgB1, False)
Clz.print(', --gen-key'.ljust(18,' ') , Clz.fgB3, False) Clz.print(', --gen-key'.ljust(18,' ') , Clz.fgB3, False)
Clz.print('LENGTH'.ljust(10,' ') , Clz.fgB1) Clz.print(''.ljust(10,' ') , Clz.fgB1)
Clz.print(' '*50+'generate a new key of optionnal LENGTH length (default:256)', Clz.fgB7) Clz.print(' '*50+'generate a new key' , Clz.fgB7)
Clz.print(' '*4+'-H ' , Clz.fgB3, False) Clz.print(' '*4+'-H ' , Clz.fgB3, False)
Clz.print('HOST'.ljust(10,' ') , Clz.fgB1, False) Clz.print('HOST'.ljust(10,' ') , Clz.fgB1, False)

View File

@ -3,7 +3,7 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # #
# software : ImpraStorage <http://imprastorage.sourceforge.net/> # # software : ImpraStorage <http://imprastorage.sourceforge.net/> #
# version : 0.4 # # version : 0.6 #
# date : 2012 # # date : 2012 #
# licence : GPLv3.0 <http://www.gnu.org/licenses/> # # licence : GPLv3.0 <http://www.gnu.org/licenses/> #
# author : a-Sansara <http://www.a-sansara.net/> # # author : a-Sansara <http://www.a-sansara.net/> #
@ -87,7 +87,8 @@ class FSplitter :
def _split(self, fromPath, hlst): def _split(self, fromPath, hlst):
"""""" """"""
rt = RuTime(eval(__CALLER__())) from impra.util import DEBUG_NOTICE, DEBUG, DEBUG_LEVEL, DEBUG_INFO
rt = RuTime(eval(__CALLER__()),DEBUG_INFO)
f = open(fromPath, 'rb+') f = open(fromPath, 'rb+')
m = mmap(f.fileno(), 0) m = mmap(f.fileno(), 0)
p = 0 p = 0
@ -577,11 +578,11 @@ class ImpraStorage:
rt = RuTime(eval(__CALLER__()),DEBUG_INFO) rt = RuTime(eval(__CALLER__()),DEBUG_INFO)
if self.idx != None : if self.idx != None :
self.ih.delete(self.idx, True) self.ih.delete(self.idx, True)
if len(self.delids) > 0 : #~ if len(self.delids) > 0 :
for i in self.delids : self.ih.delete(i, True, False) #~ for i in self.delids : self.ih.delete(i, True, False)
Clz.print('\n expunge, waiting server...\n', Clz.fgB1) #~ Clz.print('\n expunge, waiting server...\n', Clz.fgB1)
self.srv.expunge() #~ self.srv.expunge()
sleep(2) #~ sleep(2)
encData = self.index.encrypt() encData = self.index.encrypt()
msgIndex = self.mb.buildIndex(encData) msgIndex = self.mb.buildIndex(encData)
if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE : print(msgIndex.as_string()) if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE : print(msgIndex.as_string())
@ -613,7 +614,7 @@ class ImpraStorage:
"""""" """"""
lloc = [bytes(str(data[0]),'utf-8') for mid, data in enumerate(sendIds)] lloc = [bytes(str(data[0]),'utf-8') for mid, data in enumerate(sendIds)]
lsrv = self.ih.searchBySubject(subject,True) lsrv = self.ih.searchBySubject(subject,True)
return [ i for i in set(lloc).difference(set(lsrv))] return [ int(i) for i in set(lloc).difference(set(lsrv))]
def addFile(self, path, label, catg=''): def addFile(self, path, label, catg=''):
"""""" """"""
@ -622,11 +623,10 @@ class ImpraStorage:
rt = RuTime(eval(__CALLER__('"%s","%s","%s"' % (path[:13]+'...',label,catg))),DEBUG_INFO) rt = RuTime(eval(__CALLER__('"%s","%s","%s"' % (path[:13]+'...',label,catg))),DEBUG_INFO)
_, ext = splitext(path) _, ext = splitext(path)
try: try:
size = getsize(path) size = getsize(path)
if size > 0 : if size > 0 :
md5 = hash_md5_file(path) md5 = hash_sha256(path)
print() print()
Clz.print(' file : ' , Clz.fgn7, False) Clz.print(' file : ' , Clz.fgn7, False)
Clz.print(path , Clz.fgN1) Clz.print(path , Clz.fgN1)
@ -659,40 +659,42 @@ class ImpraStorage:
msg = self.mb.build(usr,'all',hlst['head'][2],self.fsplit.DIR_OUTBOX+row[1]+'.ipr') msg = self.mb.build(usr,'all',hlst['head'][2],self.fsplit.DIR_OUTBOX+row[1]+'.ipr')
mid = self.ih.send(msg.as_string(), self.rootBox) mid = self.ih.send(msg.as_string(), self.rootBox)
if mid is not None : if mid is not None :
# dont remove
status, resp = self.ih.fetch(mid[1],'(UID BODYSTRUCTURE)', True)
if status == self.ih.OK:
sendIds.append((mid[1],row))
print(' ',end='') print(' ',end='')
Clz.print('part ' , Clz.fgn7, False) Clz.print('part ' , Clz.fgn7, False)
Clz.print(str(row[0]) , Clz.fgB2, False) Clz.print(str(row[0]) , Clz.fgB2, False)
Clz.print(' sent as msg ', Clz.fgn7, False) Clz.print(' sent as msg ', Clz.fgn7, False)
Clz.print(str(mid[1]) , Clz.fgB1) Clz.print(str(mid[1]) , Clz.fgB1)
sendIds.append((mid[1],row))
else: else:
print('\n-- error occured when sending part : %s\n-- retrying' % row[0]) print('\n-- error occured when sending part : %s\n-- retrying' % row[0])
mid = self.ih.send(msg.as_string(), self.rootBox)
if mid is not None :
print('part %s sent as msg %s' % (row[0],mid[1]))
sendIds.append((mid[1],row))
else:
print('\n-- can\'t send part %s\n-- cancelling ' % row[0])
cancel = True
break
print() print()
if not cancel : if not cancel :
self.index.add(hlst['head'][3],label,hlst['head'][1],ext,ownerHash,catg,md5,bFlag,size) self.index.add(hlst['head'][3],label,hlst['head'][1],ext,ownerHash,catg,md5,bFlag,size)
done = self.saveIndex()
self.conf.set('nid', str(self.index.id),'index')
diff = self.checkSendIds(sendIds,hlst['head'][2]) diff = self.checkSendIds(sendIds,hlst['head'][2])
for mid in diff :
if mid > 0:
print(mid)
#self.ih.delete(str(mid), True, False)
print('toto')
self.conf.set('nid', str(self.index.id),'index')
if len(diff) > 0 : if len(diff) > 0 :
Clz.print(' error when sending, missing parts :', Clz.fgB1) Clz.print(' error when sending, missing parts :', Clz.fgB1)
print(diff) for mid in diff :
for mid, row in sendIds : # bugfix mid would be without +1
k = [ k for k in sendIds if len(k)>0 and int(k[0]) == int(mid+1)]
if len(k) > 0 :
row = k[0][1]
msg = self.mb.build(usr,'all',hlst['head'][2],self.fsplit.DIR_OUTBOX+row[1]+'.ipr') msg = self.mb.build(usr,'all',hlst['head'][2],self.fsplit.DIR_OUTBOX+row[1]+'.ipr')
Clz.print(' resending part ' , Clz.fgn7, False) Clz.print(' resending part ' , Clz.fgn7, False)
Clz.print(str(row[0]) , Clz.fgN2, False) Clz.print(str(row[0]) , Clz.fgN2)
mid = self.ih.send(msg.as_string(), self.rootBox) mid = self.ih.send(msg.as_string(), self.rootBox)
else : else :
print() print()
#Clz.print(' index intall files checked\n', Clz.fgB2) #Clz.print(' index intall files checked\n', Clz.fgB2)
done = self.saveIndex()
# clean # clean
for mid, row in sendIds : for mid, row in sendIds :
@ -714,6 +716,7 @@ class ImpraStorage:
print() print()
except Exception as e : except Exception as e :
print('Erroreuh')
print(e) print(e)
rt.stop() rt.stop()
return done return done
@ -739,7 +742,7 @@ class ImpraStorage:
self.ih.delete(mid, True, False) self.ih.delete(mid, True, False)
Clz.print('\n expunge, waiting pls...\n', Clz.fgB1) Clz.print('\n expunge, waiting pls...\n', Clz.fgB1)
self.ih.srv.expunge() self.ih.srv.expunge()
sleep(2) sleep(0.5)
self.index.rem(key) self.index.rem(key)
done = self.saveIndex() done = self.saveIndex()
rt.stop() rt.stop()
@ -761,11 +764,11 @@ class ImpraStorage:
rt = RuTime(eval(__CALLER__('"[%i] %s"' % (row[ImpraIndex.UID],row[ImpraIndex.LABEL]))),DEBUG_INFO) rt = RuTime(eval(__CALLER__('"[%i] %s"' % (row[ImpraIndex.UID],row[ImpraIndex.LABEL]))),DEBUG_INFO)
ck = ConfigKey(row[ImpraIndex.HASH]) ck = ConfigKey(row[ImpraIndex.HASH])
hlst = ck.getHashList(key,row[ImpraIndex.PARTS],True) hlst = ck.getHashList(key,row[ImpraIndex.PARTS],True)
ids = self._getIdsBySubject(hlst['head'][2]) ids = self.ih.searchBySubject(hlst['head'][2],True)
if len(ids) >= row[ImpraIndex.PARTS]: if len(ids) >= row[ImpraIndex.PARTS]:
for mid in ids : for mid in ids :
self.ih.downloadAttachment(mid,self.fsplit.DIR_INBOX) self.ih.downloadAttachment(mid,self.fsplit.DIR_INBOX, True)
if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE : if DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE :
print(hlst['head']) print(hlst['head'])
for v in hlst['data']: for v in hlst['data']:
@ -781,13 +784,13 @@ class ImpraStorage:
else : else :
print() print()
Clz.print(' == `' , Clz.bg3+Clz.fgB4, False) Clz.print(' == `' , Clz.BG3+Clz.fgB1, False)
Clz.print(row[ImpraIndex.LABEL] , Clz.bg3+Clz.fgB1, False) Clz.print(row[ImpraIndex.LABEL] , Clz.BG3+Clz.fgB4, False)
Clz.print('` invalid count parts ' , Clz.bg3+Clz.fgB4) Clz.print('` invalid count parts ' , Clz.BG3+Clz.fgB1, False)
Clz.print(str(len(ids)) , Clz.bg3+Clz.fgB1) Clz.print(str(len(ids)) , Clz.BG3+Clz.fgB4, False)
Clz.print('/' , Clz.bg3+Clz.fgB4) Clz.print('/' , Clz.BG3+Clz.fgB1, False)
Clz.print(str(len(row[ImpraIndex.PARTS])) , Clz.bg3+Clz.fgB1) Clz.print(str(row[ImpraIndex.PARTS]) , Clz.BG3+Clz.fgB4, False)
Clz.print(' == ' , Clz.bg3+Clz.fgB4) Clz.print(' == ' , Clz.BG3+Clz.fgB1)
print() print()
rt.stop() rt.stop()

View File

@ -3,7 +3,7 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # #
# software : ImpraStorage <http://imprastorage.sourceforge.net/> # # software : ImpraStorage <http://imprastorage.sourceforge.net/> #
# version : 0.4 # # version : 0.6 #
# date : 2012 # # date : 2012 #
# licence : GPLv3.0 <http://www.gnu.org/licenses/> # # licence : GPLv3.0 <http://www.gnu.org/licenses/> #
# author : a-Sansara <http://www.a-sansara.net/> # # author : a-Sansara <http://www.a-sansara.net/> #
@ -334,23 +334,23 @@ class ImapHelper:
else : else :
status, resp = self.srv.store(mid, '+FLAGS', '\\Deleted') status, resp = self.srv.store(mid, '+FLAGS', '\\Deleted')
Clz.print(' flag msg ' , Clz.fgn7, False) Clz.print(' flag msg ' , Clz.fgn7, False)
Clz.print(str(mid) , Clz.fgB1, False) Clz.print(str(int(mid)), Clz.fgB1, False)
Clz.print(' as deleted', Clz.fgn7) Clz.print(' as deleted', Clz.fgn7)
if expunge : if expunge :
Clz.print('\n expunge, waiting server...\n', Clz.fgB1) Clz.print('\n expunge, waiting server...\n', Clz.fgB1)
self.srv.expunge() self.srv.expunge()
sleep(2) sleep(0.5)
rt.stop() rt.stop()
return status == self.OK return status == self.OK
def downloadAttachment(self, msg, toDir='./'): def downloadAttachment(self, msg, toDir='./', byUid=False):
"""""" """"""
from impra.util import DEBUG, DEBUG_LEVEL, DEBUG_NOTICE, DEBUG_INFO from impra.util import DEBUG, DEBUG_LEVEL, DEBUG_NOTICE, DEBUG_INFO
rt = RuTime(eval(__CALLER__('%i' % int(msg))),DEBUG_INFO) rt = RuTime(eval(__CALLER__('%i' % int(msg))),DEBUG_INFO)
if not isinstance(msg, Message) : if not isinstance(msg, Message) :
msg = self.email(msg) msg = self.email(msg,byUid)
for part in msg.walk(): for part in msg.walk():
filename = part.get_filename() filename = part.get_filename()
if filename != None and DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE : print(filename) if filename != None and DEBUG and DEBUG_LEVEL <= DEBUG_NOTICE : print(filename)

View File

@ -3,7 +3,7 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # #
# software : ImpraStorage <http://imprastorage.sourceforge.net/> # # software : ImpraStorage <http://imprastorage.sourceforge.net/> #
# version : 0.4 # # version : 0.6 #
# date : 2012 # # date : 2012 #
# licence : GPLv3.0 <http://www.gnu.org/licenses/> # # licence : GPLv3.0 <http://www.gnu.org/licenses/> #
# author : a-Sansara <http://www.a-sansara.net/> # # author : a-Sansara <http://www.a-sansara.net/> #
@ -187,7 +187,7 @@ def __CALLER__(args=''):
""" """
global DEBUG_LEVEL, DEBUG, DEBUG_WARN global DEBUG_LEVEL, DEBUG, DEBUG_WARN
val = "self.__class__.__name__+'.%s' % stack()[1][3]+'("+quote_escape(args)+") " val = "self.__class__.__name__+'.%s' % stack()[1][3]+'("+quote_escape(args)+") "
if DEBUG and DEBUG_LEVEL<=DEBUG_WARN : val += "l:'+str(stack()[1][2])" if DEBUG and DEBUG_LEVEL<=DEBUG_WARN : val += "l:'+str(stack()[1][2]) "
else: val += "'" else: val += "'"
return val return val
@ -300,6 +300,15 @@ class IniFile:
with open(path, mode='w', encoding='utf-8') as o: with open(path, mode='w', encoding='utf-8') as o:
o.write(content) o.write(content)
def getSections(self):
""""""
l = {}
for s in self.dic:
section = s.split('.')
if len(section)> 1 and not section[0] in l :
l[section[0]] = 1
return [k for i,k in enumerate(l)]
def toString(self,section='*'): def toString(self,section='*'):
"""""" """"""
content = '' content = ''
@ -317,7 +326,7 @@ class IniFile:
else : main += k+' = '+self.dic[s][k]+'\n' else : main += k+' = '+self.dic[s][k]+'\n'
return main + content return main + content
def print(self,section='*'): def print(self,section='*', withoutSectionName=False):
"""""" """"""
a = '' a = ''
for s in self.dic: for s in self.dic:
@ -326,7 +335,9 @@ class IniFile:
#~ if section=='*': content += '\n['+s+']\n' #~ if section=='*': content += '\n['+s+']\n'
#~ else : content += '\n['+s[len(section)+1:]+']\n' #~ else : content += '\n['+s[len(section)+1:]+']\n'
print() print()
if not withoutSectionName :
Clz.print('['+s+']', Clz.fgB3) Clz.print('['+s+']', Clz.fgB3)
else: Clz.print('['+s.split('.')[1]+']', Clz.fgB3)
for k in sorted(self.dic[s]): for k in sorted(self.dic[s]):
k = k.rstrip(' ') k = k.rstrip(' ')
if s!='main' : if s!='main' :
@ -378,6 +389,10 @@ class StrIterator:
self.i += 1 self.i += 1
return self.d[self.i-1] return self.d[self.i-1]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ class Coloriz ~~
class Coloriz: class Coloriz:
_MARKER = '' _MARKER = ''

View File

@ -3,7 +3,7 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # #
# software : ImpraStorage <http://imprastorage.sourceforge.net/> # # software : ImpraStorage <http://imprastorage.sourceforge.net/> #
# version : 0.4 # # version : 0.6 #
# date : 2012 # # date : 2012 #
# licence : GPLv3.0 <http://www.gnu.org/licenses/> # # licence : GPLv3.0 <http://www.gnu.org/licenses/> #
# author : a-Sansara <http://www.a-sansara.net/> # # author : a-Sansara <http://www.a-sansara.net/> #
@ -31,6 +31,11 @@ from impra.util import IniFile, RuTime, get_file_path
from impra.cli import Cli from impra.cli import Cli
import sys, os import sys, os
# TODO
# - check encrypt marker on crypt file
# - readjust cli commands
# - write help in colors
if __name__ == '__main__': if __name__ == '__main__':
Cli(get_file_path(__file__ )) Cli(get_file_path(__file__ ))

View File

@ -24,14 +24,17 @@ if 'bdist_msi' in sys.argv:
exe = Executable( exe = Executable(
script="imprastorage.py", script="imprastorage.py",
base=None, base=None,
targetName="ImpraStorage.exe" targetName="ImpraStorage.exe",
targetDir="lib",
shortcutName="ImpraStorage",
) )
setup( setup(
name="ImpraStorage.exe", name="ImpraStorage.exe",
version="0.5", version="0.6",
author="Me", author="a-Sansara",
description="Copyright 2012", description="ImpraStorage provided a private imap access to store large files. License GNU GPLv3 Copyright 2012 pluie.org",
executables=[exe], executables=[exe],
include-files=('./launcher.bat','./launcher.bat')
scripts=[ scripts=[
'install.py' 'install.py'
] ]
@ -40,6 +43,6 @@ else :
setup( name = "ImpraStorage", setup( name = "ImpraStorage",
version = "0.5", version = "0.5",
description = "ImpraStorage an imap private access storage", description = "mpraStorage provided a private imap access to store large files",
options = {"build_exe": build_exe_options}, options = {"build_exe": build_exe_options},
executables = [Executable("imprastorage.py", base=base)]) executables = [Executable("imprastorage.py", base=base)])