… | |
… | |
7 | BEGIN { require "mymap.pl" }; |
7 | BEGIN { require "mymap.pl" }; |
8 | |
8 | |
9 | $/ = $CRLF; |
9 | $/ = $CRLF; |
10 | |
10 | |
11 | my $port = new Coro::Socket |
11 | my $port = new Coro::Socket |
12 | LocalPort => "imap2", |
12 | LocalPort => "imap", |
13 | ReuseAddr => 1, |
13 | ReuseAddr => 1, |
14 | Listen => 1, |
14 | Listen => 1, |
15 | or die; |
15 | or die; |
16 | |
16 | |
17 | sub slog { |
17 | sub slog { |
… | |
… | |
55 | } |
55 | } |
56 | \@r; |
56 | \@r; |
57 | } |
57 | } |
58 | |
58 | |
59 | sub literal { |
59 | sub literal { |
60 | "{".length($_[0])."}\015\012$_[0]"; |
60 | "{" . (length $_[0]) . "}\015\012$_[0]"; |
61 | } |
61 | } |
62 | |
62 | |
63 | sub handle_connection { |
63 | sub handle_connection { |
64 | my $fh = shift; |
64 | my $fh = shift; |
65 | |
65 | |
… | |
… | |
93 | $bid = 0; |
93 | $bid = 0; |
94 | @mid = (); |
94 | @mid = (); |
95 | }; |
95 | }; |
96 | |
96 | |
97 | #resp $fh, "*", "OK IMAP4 service ready."; |
97 | #resp $fh, "*", "OK IMAP4 service ready."; |
98 | resp $fh, "*", "PREAUTH IMAP4 service ready."; $uid = 1; |
98 | resp $fh, "*", "PREAUTH IMAP4 service ready."; #$uid = 1; |
99 | CMD: |
99 | CMD: |
100 | while (<$fh>) { |
100 | while (<$fh>) { |
101 | /^(\S+)(?: (\S+)([^\015\012]*))?$CRLF$/os or last; |
101 | /^(\S+)(?: (\S+)([^\015\012]*))?$CRLF$/os or last; |
102 | my ($tag, $cmd, $arg) = ($1, $2, $3); |
102 | my ($tag, $cmd, $arg) = ($1, $2, $3); |
103 | my @arg; |
103 | my @arg; |
104 | $cmd = lc $cmd; |
104 | $cmd = lc $cmd; |
105 | while () { |
105 | while () { |
106 | if ($arg =~ /\G "((?:[^"\\]*|\\.))"/gc |
106 | if ($arg =~ /\G "((?:[^"\\]*|\\.))"/gc |
|
|
107 | #|| $arg =~ /\G ([^"(){ \x00-\x1f*%\\]+)/gc # ] is allowed... |
107 | || $arg =~ /\G ([^"(){ \x00-\x1f*%\\]+)/gc |
108 | || $arg =~ /\G ([^"(){ \x00-\x1f%\\]+)/gc # evolution-fix |
108 | || $arg =~ /\G \(($RE_pgrp)\)/gc) { |
109 | || $arg =~ /\G \(($RE_pgrp)\)/gc) { |
109 | push @arg, $1; |
110 | push @arg, $1; |
110 | } elsif ($arg =~ /\G {(\d+)}$/gc) { |
111 | } elsif ($arg =~ /\G {(\d+)}$/gc) { |
111 | resp $fh, $tag, "literals not yet implemented"; |
112 | resp $fh, $tag, "literals not yet implemented"; |
112 | next CMD; |
113 | next CMD; |
… | |
… | |
120 | } else { |
121 | } else { |
121 | die; |
122 | die; |
122 | } |
123 | } |
123 | } |
124 | } |
124 | |
125 | |
125 | slog 9,"<<< $tag|$cmd|@arg";#d# |
126 | slog 9, "<<< $tag|$cmd|@arg";#d# |
126 | if ($cmd eq "capability") { |
127 | if ($cmd eq "capability") { |
127 | resp $fh, $tag, "CAPABILITY IMAP4", "OK"; |
128 | resp $fh, $tag, "CAPABILITY IMAP4", "OK"; |
128 | } elsif ($cmd eq "noop") { |
129 | } elsif ($cmd eq "noop") { |
129 | resp $fh, $tag, "OK"; |
130 | resp $fh, $tag, "OK"; |
130 | # bah! |
131 | # bah! |
… | |
… | |
266 | $sql_head = "header"; |
267 | $sql_head = "header"; |
267 | $s = sub { "RFC822.HEADER ".literal($head) }; |
268 | $s = sub { "RFC822.HEADER ".literal($head) }; |
268 | } elsif ($s eq "rfc822") { |
269 | } elsif ($s eq "rfc822") { |
269 | $sql_body = "body"; $sql_head = "header"; |
270 | $sql_body = "body"; $sql_head = "header"; |
270 | $s = sub { "RFC822 ".literal($head.$CRLF.$body) }; |
271 | $s = sub { "RFC822 ".literal($head.$CRLF.$body) }; |
|
|
272 | } elsif ($s eq "body.peek[0]") {#d# evolution-bug |
|
|
273 | $sql_head = "header"; |
|
|
274 | $s = sub { "BODY[0] ".literal($head) }; |
271 | } elsif ($s eq "rfc822.header.lines") { |
275 | } elsif ($s eq "rfc822.header.lines") { |
272 | $sql_head = "header"; |
276 | $sql_head = "header"; |
273 | my $re; |
277 | my $re; |
274 | $re = '(?i:^((?:' |
278 | $re = '(?i:^((?:' |
275 | . (join "|", @{split_pgrp shift @$sel}) |
279 | . (join "|", @{split_pgrp shift @$sel}) |
… | |
… | |
353 | print $fh "$r$tag OK\015\012"; |
357 | print $fh "$r$tag OK\015\012"; |
354 | #resp $fh, $tag, "OK"; |
358 | #resp $fh, $tag, "OK"; |
355 | } |
359 | } |
356 | |
360 | |
357 | } else { |
361 | } else { |
358 | resp $fh, $tag, "BAD command not understood"; |
362 | resp $fh, $tag, "BAD command not understood (nocommand)"; |
359 | } |
363 | } |
360 | |
364 | |
361 | # well... |
365 | # well... |
362 | } else { |
366 | } else { |
363 | resp $fh, $tag, "BAD command not understood"; |
367 | resp $fh, $tag, "BAD command not understood (notmailbox)"; |
364 | } |
368 | } |
365 | |
369 | |
366 | } else { |
370 | } else { |
367 | resp $fh, $tag, "BAD command not understood"; |
371 | resp $fh, $tag, "BAD command not understood (notauth)"; |
368 | } |
372 | } |
369 | } |
373 | } |
370 | }; |
374 | }; |
371 | if ($@) { |
375 | if ($@) { |
372 | resp $fh, "*", "BYE"; |
376 | resp $fh, "*", "BYE"; |