Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why are you trying to get the <strong>shortest</strong> possible program first? Start with a correct solution and then edit it to you can't remove any more. Syntax and typing are not going to be the bottlenecks for a correct solution. Even if your program is longer than anyone else's, if you are the only one who does it correctly, you still win. :)</p> <p>Read <a href="http://www.faqs.org/rfcs/rfc2822.html" rel="nofollow noreferrer">RFC 2822, "Internet Message Format"</a> to see what you have to handle.</p> <p>Then, look at the existing email parsing libraries that already exist to see the shenanigans that they have to handle. Once you think you have a solution because you follow the RFC, start working on all of the broken mailers.</p> <p>If you are just trying to get work done, use the right tool. This is a job for formail if you just want to play with messages, but it you have to write tight code that will run on all the messages passing through your network, then something like <a href="http://opensource.sf-tec.de/Qsmtp/" rel="nofollow noreferrer">qsmtp</a> (the mod_perl for MTAs) might be what you want.</p> <p>As far why you have to do this, what did the instructor say when you asked? You should get into the habit of specifying the desired end state and constraints for any assignment, whether in school or in a "real" job.</p> <hr> <p>Here's a proper program to finish the task correctly. Mine's a bit long because I also read all of the emails from the source (which can be almost any common email storage format such as mbox, maildir, and so on) and I extract just the header from each message. This is only 51 characters: </p> <pre><code> formail -s formail -c -XTo: -XFrom: -XCc: &lt;my_inbox </code></pre> <p>If you'd rather have a Perl solution so you have a little more control over the output, here's that too:</p> <pre> #!/usr/bin/perl use Email::Folder; my $folder = Email::Folder->new($ARGV[0]); foreach my $message ( $folder->messages ) { print join "\n", map { my $h = $message->header( $_ ); defined $h ? "$_: $h " : (); } qw(From To Cc); print "\n\n"; } </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload