6 # this is a sample cgi script to accept darcs patches via POST
7 # it simply takes patches and places them in a Maildir style
10 # set this to the maildir you wish patches to be sent to.
11 my $maildir = "/tmp/maildir";
15 print "Status: 500 Error accepting patch\n";
16 print "Content-Type: text/plain\n\n";
17 print($m || "There was an error processing your request");
23 print "Content-Type: text/plain\n\n";
24 print "Thank you for your contribution!\n";
29 if($ENV{CONTENT_TYPE
} eq 'message/rfc822') {
30 my $m = start_message
($maildir) or error_page
("could not open maildir: $maildir");
32 my ($totalbytes,$bytesread,$buffer);
34 $bytesread=read(STDIN
,$buffer,1024);
36 $totalbytes += $bytesread;
38 my $r = end_message
($m);
39 $r ? error_page
($r) : success_page
();
40 } elsif($ENV{CONTENT_TYPE
}) {
41 error_page
("invalid content type, I expect something of message/rfc822");
43 error_page
("This url is for accepting darcs patches");
50 my $base_name = sprintf("patch-%d-%d-0000", $temp_dir, $$, time());
53 until (defined(fileno(FH
)) || $count++ > 100) {
54 $base_name =~ s/-(\d+)$/"-" . (1 + $1)/e;
55 sysopen(FH
, "$temp_dir/$base_name", O_WRONLY
|O_EXCL
|O_CREAT
);
57 defined(fileno(FH
)) ?
return (*FH
, $base_name) : return ();
62 my ($fh,$fname) = temp_file
("$maildir/tmp") or return undef;
63 return { maildir
=> $maildir, fh
=> $fh, filename
=> $fname };
68 close $m->{fh
} or return "$!: $m->{filename} - Could not close filehandle";
69 link "$m->{maildir}/tmp/$m->{filename}", "$m->{maildir}/new/$m->{filename}" or return "$@: $m->{filename} - could not link to new";
70 unlink "$m->{maildir}/tmp/$m->{filename}";