hi all , am new in perl and I am modifying a perl script(see below).... and am trying to use the MIME mode to extract a txt file..... I' m having some problems with the Parser, i have an email coming in that i want to convert to csv text ... is coming as text/plain.... format and also some other formats like text html etc..... how can I get the file to csv format? This is the file that am trying to convert Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US, en-AU Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 MIME-Version: 1.0 DQoNClRlY2hub2xvZ3kgTWFuYWdlcg0KSVAgQ2FsbGluZyBTb2x1dGlvbnMgYW5kIENQRSBNYW5h Z2VtZW50DQpDb252ZXJnZWQgQ2FsbGluZyBhbmQgVUMgU29sdXRpb25zDQo2MSAoMCkzIDg2NDcg
#! /usr/bin/perl open FILE,">>/tmp/SRP_RMS.xlog"; print FILE "\nInitialising\n"; #filename = $ARGV[0]; my $dbh = DBI->connect($dsn,$user,$pass) or die "Can't Connect to the DB: $DBI::errstr\n"; #open FILE, $filename; $indata=0; #$csv = Text::CSV->new(); #$processed = 0; use MIME::Parser; $parser = new MIME::Parser; $output = "/tmp/mimex"; $parser->output_dir($output); my $entity = $parser->read(\*STDIN); my $num_parts = $entity->parts; if($num_parts > 0) { for(my $i = 0; $i < $num_parts;$i++) { my $part = $entity->parts($i); my $type = lc $part->mime_type; my $bh = $part->bodyhandle; print FILE "Type: ".$type."\n"; if($type eq 'text/plain') { print FILE "processing: ".$bh->{MB_Path}."\n"; open CSVFILE, "<$bh->{MB_Path}"; #$csv = Text::CSV->new(); #$processed = 0; while (<CSVFILE>) { $line = $_; if($line =~ /^$/) { } elsif ($indata ==0)


In reply to Perl MIME - Open file by Pan20

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.