Thread Code evaluation (6 answers)
Opened by esskar at 2004-02-27 06:03

esskar
 2004-02-27 06:03
#14354 #14354
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
sub _toporretr
{
  my($self, %args) = @_;

  my $msgidx = $args{MSGID} || 1;
  my $lines = $args{LINES} || 0;
  my $cmd = $args{CMD};
  my $fh = $args{FH};
  my $nohead = $args{NOHEAD};

  $lines =~ /\d+/ or $lines = 0;

  if($cmd eq POP3CMD_TOP) { $self->print(POP3CMD_TOP." $msgidx $lines", $self->eol()); }
  else { $self->print(POP3CMD_RETR." $msgidx", $self->eol()); }

  my $line = $self->getline();
  chomp $line;

  my $buflen = 0;

  $line =~ /^\+OK/ or $self->message("Bad return from $cmd: $line") and return;
  $line =~ /^\+OK (\d+) / and $buflen = $1;

  my $retval = '';
  while(defined($line = $self->getline()))
  {      
     unless($nohead)
     {
        $line =~ /^\.\s*$/ and last;
        $line =~ s/^\.\././;
        $fh ? (print $fh $line) : ($retval .= $line);
     }
     $nohead and $line =~ /^\s*$/ and $nohead = 0;
  }

  return $fh ? 1 : wantarray ? split(/\r?\n/, $retval) : $retval;
}

sub header
{
  my($self, $msgid, $lines, $fh) = @_;

  return $self->_toporretr(CMD => POP3CMD_TOP, MSGID => $msgid, LINES => $lines, FH => $fh);
}

sub header_body
{
  my($self, $msgid, $fh) = @_;

  return $self->_toporretr(CMD => POP3CMD_RETR, MSGID => $msgid, FH => $fh);
}

sub body
{
  my($self, $msgid, $fh) = @_;

  return $self->_toporretr(CMD => POP3CMD_RETR, MSGID => $msgid, FH => $fh, NOHEAD => 1);
}


Wie findet ihr diesen code? Was macht er eurer Meinung nach?

PS: Ist von mir! Will nur mal schauen, wie ihr es machen würdet und vielleicht auch warum?!?\n\n

<!--EDIT|esskar|1077854904-->

View full thread Code evaluation