I'm trying to gather some mail and save it. I don't get why it isn't saved
as expected.
==========================================================================
import poplib, socket, sys
from configparser import Error as ProtocolError
args= sys.argv[1:] # this is fake but is here as example
from configparser import Error as ProtocolError
args= sys.argv[1:] # this is fake but is here as example
def Pop3_access(*args):
'''Accessing a pop server, doing a function and return a result'''
'''Accessing a pop server, doing a function and return a result'''
func= args[0]; args= args[1:]
try:
pop= poplib.POP3(srv_info[0])
pop.user(srv_info[1])
pop.pass_(srv_info[2])
except (poplib.error_proto):
raise ProtocolError
except (socket.timeout,socket.gaierror):
try: pop.quit()
except NameError: pass # it wasn't started
return
result= func(pop, args)
pop.quit()
return result
try:
pop= poplib.POP3(srv_info[0])
pop.user(srv_info[1])
pop.pass_(srv_info[2])
except (poplib.error_proto):
raise ProtocolError
except (socket.timeout,socket.gaierror):
try: pop.quit()
except NameError: pass # it wasn't started
return
result= func(pop, args)
pop.quit()
return result
def func(pop, N):
...
msg= Pop3_access(func, 4)
from io import BytesIO as B
fp= B()
for l in msg[1]:
from io import BytesIO as B
fp= B()
for l in msg[1]:
... fp.write('\n'.encode())
...
34
1
50
1
63
1
65
1
36
1
52
1
41
1
114
1
45
1
38
1
74
1
56
1
37
1
34
1
28
1
23
1
33
1
56
1
57
1
17
1
44
1
31
1
54
1
30
1
30
1
1
31
1
1
39
1
1
12
1
32
1
49
1
1
6
1
64
1
68
1
1
from mailbox import mbox as Mbx
mbx= Mbx('/tmp/mb', True)
mbx.add(fp)
mbx= Mbx('/tmp/mb', True)
mbx.add(fp)
mbx.get_message(0)
print(mbx.get_message(0))
>>>
===================================================================
The result is an empty message, but the fp.getvalue() shows file-like
stream.
Am I missing some point?
--
goto /dev/null