Problems extracting attachment from email

2005-04-07 Thread foten
Hi community,

This is the task I'm struggling with:
- A user sends me an email with the subject '*3gp*'
  including an attached .3gp-file.
- I then fetch that email, extracts the attachement and stores
  it localy as a file.
- I then run a python-script that parses the stored file
  and generates an excel-file with statistics of that file
  at a shared driver.
  
I'm using getmail (http://pyropus.ca/software/getmail/)
(running on cygwin with cygwin python 2.4)
and the filter function provided to fetch my mail. getmail
starts my filter script and the mail is send using stdin.

I then read from stdin using
sys.stdin.read()
and the message is stored locally. The content of this stored file
is exactly the same as the mail sent to me.

I then parse that message using
fp = open(tmp_file,'rb')
p = email.Parser.Parser()

The problem I'm having is when I'm trying to extract the
attachement using
f=open(Filename, "wb")
f.write(msg.get_payload(decode=1))
f.close()
Not the whole message is decoded and stored!
When only trying
f.write(msg.get_payload())
I see that the last 255 bytes are missing.

How is this possible, I receive every last byte from stdin?

I then tried calling my windows python installation (2.4) instead of
the cygwin thingie, but that didn't work either.

Doing this using IDLE for windows or a cmdprompt for cygwin works
great!

Any ideas 'bout what I'm doing wrong here?

cheers

//Fredrik
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems extracting attachment from email

2005-04-08 Thread foten
Lee Harr <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> On 2005-04-07, foten <[EMAIL PROTECTED]> wrote:
> > The problem I'm having is when I'm trying to extract the
> > attachement using
> > f=open(Filename, "wb")
> > f.write(msg.get_payload(decode=1))
> > f.close()
> > Not the whole message is decoded and stored!
> > When only trying
> > f.write(msg.get_payload())
> > I see that the last 255 bytes are missing.
> >
> 
> 
> What happens if you do...
> 
> m = msg.get_payload(decode=1)
> f.write(m)
> f.write(m)
> f.close()
> ?
> 
> Just wondering if maybe some buffer not
> being flushed properly.
> 
> Maybe could replace the 2nd f.write()
> with an f.flush()
Lee Harr <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> On 2005-04-07, foten <[EMAIL PROTECTED]> wrote:
> > The problem I'm having is when I'm trying to extract the
> > attachement using
> > f=open(Filename, "wb")
> > f.write(msg.get_payload(decode=1))
> > f.close()
> > Not the whole message is decoded and stored!
> > When only trying
> > f.write(msg.get_payload())
> > I see that the last 255 bytes are missing.
> >
> 
> 
> What happens if you do...
> 
> m = msg.get_payload(decode=1)
> f.write(m)
> f.write(m)
> f.close()
> ?
> 
> Just wondering if maybe some buffer not
> being flushed properly.
> 
> Maybe could replace the 2nd f.write()
> with an f.flush()

Thanx for the ideas!

If I do
f.write(m)
f.write(m)
nothing is changed. After the first write I'm missing 255 bytes and the 
second write just doubles the data. After this I'm missing 510 bytes.
Doing a flush doesn't help either, if I'm not misstaken, calling close()
on a file inplicitly calls flush().

get_payload() fails to deliver the correct amount of data, in this case ~82k...

This drives my crazy!
-- 
http://mail.python.org/mailman/listinfo/python-list