Loading ...
Sorry, an error occurred while loading the content.

freemail code -- unfinished

Expand Messages
  • Robin
    #!/usr/bin/perl package main; my $m = new freemail; $m - mail (); package freemail; require Exporter; use Tk; require Tk; use Net::POP3; use Net::SMTP; use
    Message 1 of 3 , Jul 27, 2006
    • 0 Attachment
      #!/usr/bin/perl

      package main;
      my $m = new freemail;
      $m -> mail ();

      package freemail;

      require Exporter;
      use Tk;
      require Tk;
      use Net::POP3;
      use Net::SMTP;
      use strict;

      our @ISA = qw (Exporter);
      our @EXPORt = qw (new);

      my $pop3;
      my $wizz;
      my @msgs;
      my $username;
      my $name;
      my $email;
      my $password;
      my $smtpserver;
      my $smtppassword;
      my $popserver;
      my $smtpusername;
      my @setdata;
      my $maillist;
      my %msgsfinal;
      my $currmail;
      sub new {
      my $class = shift;
      my $o = {};
      bless ($o, $class);
      $o -> {USERDATA} = {};
      return $o;
      }

      my $mwin;
      sub mail () {

      my $self = shift;
      $mwin = new MainWindow (-title=>"Freemail");

      $mwin -> focusForce();
      $mwin -> resizable (0,0);
      my $menu = $mwin -> Menu ();
      my $file = $menu -> cascade (-label=>'File');
      $file -> command (-label=>"Save Mail Message As...",
      -command=>\&savemailas);
      $file -> separator ();
      $file -> command (-label=>"Exit", -command=>sub { exit });
      my $configure = $menu -> cascade (-label=>"Configure");
      $configure -> command (-label=>"Configure Mail...",
      -command=>\&setupwizzard);

      my $t = $mwin -> Table (-scrollbars=>0) -> pack();
      my $f1 = $t -> Frame ();
      $t -> put (0, 0, $f1);
      my $f2 = $t -> Frame (-background=>'cyan');
      $t -> put (0, 1, $f2);
      my $f3 = $t -> Frame (-background=>'lightgreen');
      $t -> put (1, 1, $f3);

      my $checkmail = $f1 -> Button (-text=>'Check Mail', -command=>sub {
      checkmail ($self); } ) -> pack (-fill=>'x');
      my $sendmail = $f1 -> Button (-text=>'New Mail', -command=>sub {
      sendmail ( $self ) }) ->pack (-fill=>'x');
      my $reply = $f1 -> Button (-text=>'Reply', -command=>sub { sendmail
      ($self, "reply"); }) -> pack (-fill=>'x');
      my $forward = $f1 -> Button (-text=>'Forward', -command=>sub {
      sendmail ($self, "forward"); }) -> pack (-fill=>'x');
      my $addressbook = $f1 -> Button (-text=>"Address Book",
      -command=>sub { addressbook ($self); }) -> pack (-fill=>'x');



      $maillist = $f2 -> Scrolled ("HList", -browsecmd=>\&displaymail,
      -scrollbars=>'se', -background=>'cyan') -> pack (-fill=>'x');
      $currmail = $f3 -> Scrolled ("Text", -scrollbars=>'se', -width=>90,
      -height=>30, -backgroun=>'lightgray') -> pack (-fill=>'x');
      $mwin -> configure (-menu=>$menu);


      if (-e "settings_freemail.ini") {
      getconfig ($self);
      }
      else {
      my $d = $mwin -> Dialog (-text=>"Would you like to configure
      your email now?", -title=>"Freemail", -buttons=>["OK", "Cancel"]);
      my $g = $d -> Show ();
      if ($g eq "OK") {
      setupwizzard ();
      }
      }

      MainLoop();


      }

      sub displaymail {
      my @mailsel = $maillist -> info ('selection');
      if (@mailsel > 1) {
      return;
      }
      my $s;
      $s = substr ($mailsel[0], 0, 1);

      $currmail -> Contents();
      $currmail -> Contents ($msgsfinal{$s});
      }

      sub getconfig {
      my $self = shift;
      open (F, "settings_freemail.ini");

      my @conf = <F>;
      close F;
      chomp @conf;
      # open (F, ">settings_freemail.ini");

      # print F $username -> get();
      # print F "\n";
      # print F $password -> get ();
      # print F "\n";
      # print F $popserver -> get ();
      # print F "\n";
      # print F $smtpserver -> get ();
      # print F "\n";
      # print F $smtpusername -> get ();
      # print F "\n";
      # print F $smtppassword -> get ();
      # print F "\n";
      # print F $name -> get ();
      # print F "\n";
      # print F $email -> get ();
      # print F "\n";
      # close F;
      $self -> {USERDATA}{USERNAME} = $conf[0];
      $self -> {USERDATA}{PASSWORD} = $conf[1];
      $self -> {USERDATA}{POPSERVER} = $conf[2];
      $self -> {USERDATA}{SMTPSERVER} = $conf[3];
      $self -> {USERDATA}{SMTPUSERNAME} = $conf[4];
      $self -> {USERDATA}{SMTPPASSWORD} = $conf[5];
      $self -> {USERDATA}{NAME} = $conf[6];
      $self -> {USERDATA}{EMAIL} = $conf[7];

      }
      sub checkmail {

      my $self = shift;
      print $self -> {USERDATA}{USERNAME};
      print $self -> {USERDATA}{PASSWORD};
      print $self -> {USERDATA}{POPSERVER};
      if (! -e "settings_freemail.ini") {
      setupwizzard ();
      return;
      }
      $pop3 = Net::POP3 -> new ($self->{USERDATA}{POPSERVER});
      if (! $pop3 -> login ($self->{USERDATA}{USERNAME},
      $self->{USERDATA}{PASSWORD})) {
      $mwin -> Dialog (-title=>"Error", -text=>"There was an error
      logging in. Check your login information") -> Show ();
      return;
      }
      else {
      my $list = $pop3 -> list;
      my $msg;
      foreach my $msgnum (keys %$list) {
      $msg = $pop3 -> get ($msgnum);
      push @msgs, join '', @$msg;
      }
      }
      if (@msgs) {
      print scalar @msgs;
      my @s;
      my $from;

      my $sub;
      my $count=0;
      foreach my $z (@msgs) {
      @s = split (/\n\n/, $z);
      if ($s[0] =~ m/Subject: (.+)/) {
      $sub = $1;
      }
      if ($s[0] =~ m/From: (.+)/) {
      $from = $1;
      }
      $maillist-> add ("$count", -text=>"$count. From: $from --
      Subject: $sub", -data=>"$count");
      $msgsfinal{$count} = $z;
      $count += 1;
      }
      }
      }



      sub setupwizzard {
      $wizz = $mwin -> Toplevel (-title=>'Configure Mail');
      if (-e 'settings_freemail.ini') {
      open (F, 'settings_freemail.ini');
      @setdata=<F>;
      close F;
      chomp @setdata;
      }
      my $topl = $wizz -> Label (-text=>"Configure Mail\n\n---\n",
      -font=>'Verdana') -> pack (-fill=>'x');
      my $l1 = $wizz -> Label (-text=>"POP Server") -> pack (-fill=>'x');
      $popserver = $wizz -> Entry () -> pack (-fill=>'x');
      my $l2 = $wizz -> Label (-text=>'SMTP Server') -> pack (-fill=>'x');
      $smtpserver = $wizz -> Entry () -> pack (-fill=>'x');
      my $l3 = $wizz -> Label (-text=>'POP Username') -> pack
      (-fill=>'x');
      $username = $wizz -> Entry () -> pack (-fill=>'x');
      my $l4 = $wizz -> Label (-text=>'POP Password') -> pack
      (-fill=>'x');
      $password = $wizz -> Entry () -> pack (-fill=>'x');
      my $l5 = $wizz -> Label (-text=>'SMTP Username (leave totally blank
      if you don\'t need authentication)') -> pack (-fill=>'x');
      $smtpusername = $wizz -> Entry () -> pack (-fill=>'x');
      my $l6 = $wizz -> Label (-text=>'SMTP Password (leave totally blank
      if you don\'t need authentication)') -> pack (-fill=>'x');
      $smtppassword = $wizz -> Entry () -> pack (-fill=>'x');
      my $l7 = $wizz -> Label (-text=>'Your Name') -> pack (-fill=>'x');
      $name = $wizz -> Entry () -> pack (-fill=>'x');
      my $l8 = $wizz -> Label (-text=>'Your E-Mail Address') -> pack
      (-fill=>'x');
      $email = $wizz -> Entry () -> pack (-fill=>'x');
      my $finish = $wizz -> Button (-text=>"Finish",
      -command=>\&saveconfig) -> pack (-fill=>'x');
      if (@setdata) {

      $username -> insert (0 , $setdata[0]);
      $password -> insert (0, $setdata[1]);
      $popserver -> insert (0, $setdata[2]);
      $smtpserver -> insert (0, $setdata[3]);
      $smtpusername -> insert (0, $setdata[4]);

      $smtppassword -> insert (0, $setdata[5]);
      $name -> insert (0, $setdata[6]);
      $email -> insert (0, $setdata[7]);
      }
      }

      sub saveconfig {
      if (! -e "settings_freemail.ini") {
      open (F, ">settings_freemail.ini");
      print F $username -> get();
      print F "\n";
      print F $password -> get ();
      print F "\n";
      print F $popserver -> get ();
      print F "\n";
      print F $smtpserver -> get ();
      print F "\n";
      print F $smtpusername -> get ();
      print F "\n";
      print F $smtppassword -> get ();
      print F "\n";
      print F $name -> get ();
      print F "\n";
      print F $email -> get ();
      print F "\n";
      close F;
      }
      else {
      unlink ("settings_freemail.ini");
      open (F, ">settings_freemail.ini");
      print F $username -> get();
      print F "\n";
      print F $password -> get ();
      print F "\n";
      print F $popserver -> get ();
      print F "\n";
      print F $smtpserver -> get ();
      print F "\n";
      print F $smtpusername -> get ();
      print F "\n";
      print F $smtppassword -> get ();
      print F "\n";
      print F $name -> get ();
      print F "\n";
      print F $email -> get ();
      print F "\n";
      close F;
      }
      getconfig ();
      $wizz -> destroy ();
      }

      sub strip_html ($) {

      }
      1;
      __END__
      \
      -Robin
    • Mike Southern
      What was the question?
      Message 2 of 3 , Jul 28, 2006
      • 0 Attachment
        What was the question?
      • Charles K. Clarkson
        ... When I first run the code I get these messages: Assuming require Tk::Table; at C: freemail.pl line 58 Assuming require Tk::HList; at C: freemail.pl
        Message 3 of 3 , Jul 29, 2006
        • 0 Attachment
          Robin wrote:

          : #!/usr/bin/perl
          : package main;
          : my $m = new freemail;
          : $m -> mail ();


          When I first run the code I get these messages:

          Assuming 'require Tk::Table;' at C:\freemail.pl line 58
          Assuming 'require Tk::HList;' at C:\freemail.pl line 74
          Assuming 'require Tk::Dialog;' at C:\freemail.pl line 83

          "use" these in the code.


          : package freemail;
          :
          : require Exporter;

          freemail looks like an object. It may not need to export
          anything into the caller's namespace.


          : use Tk;
          : require Tk;

          You did this in the flatland code also. Why "use" and
          "require" the same module? Read the docs on what "require" does
          different from "use". Using both shows a lack of understanding.


          : use Net::POP3;
          : use Net::SMTP;
          : use strict;
          :
          : our @ISA = qw (Exporter);
          : our @EXPORt = qw (new);

          That's a typo. Exporter isn't doing much in this module. It
          certainly isn't exporting new().

          This

          my $m = new freemail;

          Is another way to write this.

          my $m = freemail->new();

          It is not another way to write this.

          my $m = new( 'freemail' );

          There's no need to import new() into main::.


          The beginning of this object might better be written like
          this.

          package freemail;

          use strict;
          use warnings;

          # GUI
          use Tk;
          use Tk::Table;
          use Tk::HList;
          use Tk::Dialog;

          # Mail
          use Net::POP3;
          use Net::SMTP;



          Have you considered using a separate module for the GUI and
          the mail handler? These seem like two very distinct portions of an
          application.

          package freemail;

          use strict;
          use warnings;

          # Mail
          use Net::POP3;
          use Net::SMTP;

          .
          .
          .


          package freemail_GUI;

          use strict;
          use warnings;

          # GUI
          use Tk;
          use Tk::Table;
          use Tk::HList;
          use Tk::Dialog;

          .
          .
          .


          HTH,

          Charles K. Clarkson
          --
          Mobile Homes Specialist
          Free Market Advocate
          Web Programmer

          254 968-8328

          Don't tread on my bandwidth. Trim your posts.
        Your message has been successfully submitted and would be delivered to recipients shortly.