Hello Monks, I'll be honest, this is my first post here, and I'm fairly new to perl (I come from a PHP background, I'm very excited to start perl!). I've finally found a suitable project to try my (perl) hand at. I'm teaching a lab section of Engineering Computing this semester, and as part of the class, the students are to email me their work (which, so far, consists of excel workbooks). After manually saving 30-some-odd of these today, I said, "There's gotta be a better way". Enter perl. I've been doing some reading on WWW::Mechanize and have successfully implemented it... so far. I'm trying to get it to find all the submitted excel files in my inbox (done), and download them (having trouble with this). Here's what I have so far:
#!C:\perl\bin\perl.exe use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $url = 'https://webmail.my_university.edu'; $mech->get($url); # login $mech->submit_form( form_number => 0, fields => { imapuser => 'c4onastick', pass => 'my_password_here', } ); # Navigate back to the first page that contains the most recent messag +es $mech->follow_link(url_regex => qr/page=1/ ); # Find all links (messages) with Lab 2 in the subject my @links = $mech->find_all_links( text_regex => qr/lab\s*2/i ); my $content; foreach my $link (@links) { print $link->url."\n"; print $link->text."\n"; print "Following...\n"; $mech->follow_link( url => $link->url); $mech->follow_link( url_regex => qr/\.xls/i ); #link to the attach +ed excel file $content .= $mech->content; # this might be where it is breaking d +own last; # Jump out after one for testing $mech->back; } mkdir "Eng_files", 0755 or die "Couldn't create directory: $!"; chdir "Eng_files" or die "Can't change directory: $!"; open(FH, ">", "test.xls"); print "Writing out...\n"; print FH $content; print "Done.\n\n";
So far, it works, it writes out and everyone is happy, except excel. It wont let me open them (I get a funky ready-only error, I don't think its excel's fault, I think I'm doing something wrong in the perl above). I'll eventually save these with the student's name in the filename (which I can also get from the message), but for now, I need to be able to open them to grade them! Thanks in advance for your help. I really look forward to becoming part of this community! (Next project is a perl script to grade them for me!)

In reply to Downloading Excel Spreadsheets from Web-based Mail by c4onastick

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.