|
Prev: Using perl modules
Next: how to flush a file
From: jcharth on 27 Jan 2007 09:48 Hello I am trygint to get the header of a string. I dont thnk this can be done with the mime head module but may bet there is a work around. I am fetching a message to a variable called $message using LWP, i tried MIME::HEAD->read"$message" and - >from_file("$message) but now luck. May be I need a funtion that writes the buffer to the tempfolder and returns the name of the temp fie? $head = MIME::Head->read(\*STDIN); ### Parse a new header from a file, or a readable pipe: $testhead = MIME::Head->from_file("/tmp/test.hdr"); $a_b_head = MIME::Head->from_file("cat a.hdr b.hdr |");
From: Michele Dondi on 27 Jan 2007 10:31 On 27 Jan 2007 06:48:27 -0800, jcharth(a)hotmail.com wrote: >Hello I am trygint to get the header of a string. I dont thnk this can >be done with the mime head module but may bet there is a work around. >I am fetching a message to a variable called >$message using LWP, i tried MIME::HEAD->read"$message" and - The module is MIME::Head, and the above is not syntactically valid Perl: parens around method calls are mandatory except when the argument list is empty. Also, not strictly an error, but you don't need to quote $message. See perldoc -q quoting Also, reading M::H's docs I see : Before reading further, you should see MIME::Tools to make sure that : you understand where this module fits into the grand scheme of things. : Go on, do it now. I'll wait. However, it also says : ### Parse a new header from a filehandle: : $head = MIME::Head->read(\*STDIN); : : ### Parse a new header from a file, or a readable pipe: : $testhead = MIME::Head->from_file("/tmp/test.hdr"); : $a_b_head = MIME::Head->from_file("cat a.hdr b.hdr |"); Thus you can open() $message in memory: open my $fh, '<', \$message or die "D'Oh! $!\n"; my $head = MIME::Head->read($fh); Michele -- {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB=' ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_, 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
From: jcharth on 28 Jan 2007 12:12 I tried using open my $fh but $head->get returns an empty string everysingle time, if i print $message I see the full message. open my $fh, '<', \$message or die "D'Oh! $!\n"; my $head = MIME::Head->read($fh); $myTo = lc($head->get('To',0)); On Jan 27, 10:31 am, Michele Dondi <bik.m...(a)tiscalinet.it> wrote: > On 27 Jan 2007 06:48:27 -0800, jcha...(a)hotmail.com wrote: > > >Hello I am trygint to get the header of a string. I dont thnk this can > >be done with the mime head module but may bet there is a work around. > >I am fetching a message to a variable called > >$message using LWP, i tried MIME::HEAD->read"$message" and -The module is MIME::Head, and the above is not syntactically valid > Perl: parens around method calls are mandatory except when the > argument list is empty. Also, not strictly an error, but you don't > need to quote $message. See > > perldoc -q quoting > > Also, reading M::H's docs I see > > : Before reading further, you should see MIME::Tools to make sure that > : you understand where this module fits into the grand scheme of things. > : Go on, do it now. I'll wait. > > However, it also says > > : ### Parse a new header from a filehandle: > : $head = MIME::Head->read(\*STDIN); > : > : ### Parse a new header from a file, or a readable pipe: > : $testhead = MIME::Head->from_file("/tmp/test.hdr"); > : $a_b_head = MIME::Head->from_file("cat a.hdr b.hdr |"); > > Thus you can open() $message in memory: > > open my $fh, '<', \$message or die "D'Oh! $!\n"; > my $head = MIME::Head->read($fh); > > Michele > -- > {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr > (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB=' > .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_, > 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
From: Michele Dondi on 28 Jan 2007 13:04 On 28 Jan 2007 09:12:58 -0800, jcharth(a)hotmail.com wrote: >I tried using open my $fh but $head->get returns an empty string >everysingle time, if i print $message I see the full message. > >open my $fh, '<', \$message or die "D'Oh! $!\n"; > my $head = MIME::Head->read($fh); > >$myTo = lc($head->get('To',0)); Are things different if you save $message to a temporary file and parse that? I see no reason why they should, but just to be sure... oh, and I hope your perl is recent enough, but if it is not, I mean if it doesn't support open()ing scalars in memory, then I suppose it would just give you an error - either that or try to open a file with the name of the stringified reference for reading, which is unlikely to exist and would cause the program to die() anyway. I don't know for sure because I only have access to fairly recent perls. Other than this I can only quote myself: : Also, reading M::H's docs I see : : : Before reading further, you should see MIME::Tools to make sure that : : you understand where this module fits into the grand scheme of things. : : Go on, do it now. I'll wait. Did you do so? >On Jan 27, 10:31 am, Michele Dondi <bik.m...(a)tiscalinet.it> wrote: [snip full quoted content] *Please* do not top-post. If you don't know what top-posting is, then google for it. It makes very hard for us to follow the discussion properly. Michele -- {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB=' ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_, 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
From: jcharth on 28 Jan 2007 19:54 Thanks michael, the problem was i was downloading the file using as_string instead of content in lwp. i had some extra http headers. On Jan 28, 1:04 pm, Michele Dondi <bik.m...(a)tiscalinet.it> wrote: > On 28 Jan 2007 09:12:58 -0800, jcha...(a)hotmail.com wrote: > > >I tried using open my $fh but $head->get returns an empty string > >everysingle time, if i print $message I see the full message. > > >open my $fh, '<', \$message or die "D'Oh! $!\n"; > > my $head = MIME::Head->read($fh); > > >$myTo = lc($head->get('To',0));Are things different if you save $message to a temporary file and > parse that? I see no reason why they should, but just to be sure... > oh, and I hope your perl is recent enough, but if it is not, I mean if > it doesn't support open()ing scalars in memory, then I suppose it > would just give you an error - either that or try to open a file with > the name of the stringified reference for reading, which is unlikely > to exist and would cause the program to die() anyway. I don't know for > sure because I only have access to fairly recent perls. Other than > this I can only quote myself: > > : Also, reading M::H's docs I see > : > : : Before reading further, you should see MIME::Tools to make sure that > : : you understand where this module fits into the grand scheme of things. > : : Go on, do it now. I'll wait. > > Did you do so? > > >On Jan 27, 10:31 am, Michele Dondi <bik.m...(a)tiscalinet.it> wrote:[snip full quoted content] > > *Please* do not top-post. If you don't know what top-posting is, then > google for it. It makes very hard for us to follow the discussion > properly. > > Michele > -- > {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr > (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB=' > .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_, > 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
|
Pages: 1 Prev: Using perl modules Next: how to flush a file |