Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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 # 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

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (8)
    As of 2018-06-24 20:56 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.