Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I used to spend a lot of my time reading news sites. Now I spend all of my time doing it. But seriously, I found it was eating into my day, and so I resolved to get most of it over with first thing in the morning by having web pages sent to my inbox from a cron job.

What follows is my script to do this. I've ripped out various installation-specific bits, but it should still work. If I were to rewrite it, I'd probably use File::Temp to handle the temporary files rather than rely on unixisms.

Here's the code. Don't do anything annoying with it; good monks don't do that.

#!/usr/bin/env perl # mailwebpage - send a web page to someone over e-mail # created on 30/8/02001, and badly munged later. # # usage: takes two args; URL, and destination address # example: # mailwebpage http://www.tedious.com someone@elsewhere.com # if the URL happens to be a readable file, it does the right thing. use strict; use warnings; use diagnostics; use integer; use MIME::Lite; use LWP::Simple; my $url=shift; # web location if (-r $url) { # if URL is actually a file, $url = 'file:' . $url; # make it so # this'll probably foul up if we get a fs that can resolve urls... } my $recipient=shift; # e-mail recipient my @headarr = head($url); # get the http header if ($#headarr == -1) { die "Can't resolve $url\n"; # if there is nothing there } else { my $tmpfile = "/tmp/foo$$.tmp"; # actual tmp file name on system my $type = $headarr[0]; # Content-Type: getstore($url,$tmpfile); # get page to tmp file my $msg = new MIME::Lite # new mail object To =>$recipient, Subject =>$url, # URL is e-mail subject Type =>$type, Encoding =>'base64', Disposition =>'inline', Path =>$tmpfile; # these fields rooted out from old NS Communicator headers $msg->attr('Content-Base' => $url); $msg->attr('Content-Location' => $url); my $result = $msg->send; unlink $tmpfile; # better tell the good people what went down die "Can't send $url to $recipient\n" unless (defined($result)); } exit;

--
$,="\n";foreach(split('',"\3\3\3c>\0>c\177cc\0~c~``\0cc\177cc")) {$a++;$_=unpack('B8',$_);tr,01,\40#,;$b[$a%6].=$_};print@b,"\n"


In reply to Spend Less Time Surfing: Pages In Your Inbox with LWP::Simple and MIME::Lite by Willard B. Trophy

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (5)
    As of 2014-07-26 11:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (175 votes), past polls