Hi.

Here are patches for upload.cgi to support patch checking and sending with
sendmail. It has a set of parameters like sendmail command, test repo, test
command. At the moment all parameters are hardcoded in the script.

For darcs to send patches through POST there should be a 'post' file in prefs.
That file can contain http URLs and mailto: addresses. At the moment if post
file exists emails file is not read. So this 'mailto:' functionality seems
like replacing email file to me. I think we should remove it. In this case
email file contains emails and post file contains URLs.

Another issue is that darcs always sends patches through both email and
POST. I think we should try POST first and send through email only if it fails.
Or we can use 'mailto:' lines from post file to form To: header for POSTed
email, and email file for addresses we really send mail to directly.

I am not a good Perl coder, so it would be nice if someone reviews the changes.

Regards,
  Dmitry

Sat Sep 13 03:08:27 MSD 2008  Dmitry Kurochkin <[EMAIL PROTECTED]>
  * Spaces and punctuation in upload.cgi.

Sat Sep 13 03:09:53 MSD 2008  Dmitry Kurochkin <[EMAIL PROTECTED]>
  * Improve upload.cgi.
  - check if patch is valid before sending
  - use sendmail to send patches or drop to maildir

New patches:

[Spaces and punctuation in upload.cgi.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912230827] hunk ./tools/upload.cgi 29
-if($ENV{CONTENT_TYPE} eq 'message/rfc822') {
-        my $m = start_message($maildir) or error_page("could not open maildir: $maildir");
-        my $fh = $m->{fh};
-        my ($totalbytes,$bytesread,$buffer);
-        do {
-            $bytesread=read(STDIN,$buffer,1024);
-            print $fh $buffer;
-            $totalbytes += $bytesread;
-        } while($bytesread);
-        my $r = end_message($m);
-        $r ? error_page($r) : success_page();
-} elsif($ENV{CONTENT_TYPE}) {
+if ($ENV{CONTENT_TYPE} eq 'message/rfc822') {
+    my $m = start_message($maildir) or error_page("could not open maildir: $maildir");
+    my $fh = $m->{fh};
+    my ($totalbytes, $bytesread, $buffer);
+    do {
+        $bytesread = read(STDIN, $buffer, 1024);
+        print $fh $buffer;
+        $totalbytes += $bytesread;
+    } while ($bytesread);
+    my $r = end_message($m);
+    $r ? error_page($r) : success_page();
+} elsif ($ENV{CONTENT_TYPE}) {
hunk ./tools/upload.cgi 43
-    error_page("This url is for accepting darcs patches");
+    error_page("This url is for accepting darcs patches.");
hunk ./tools/upload.cgi 62
-    my ($fh,$fname) = temp_file("$maildir/tmp") or return undef;
+    my ($fh, $fname) = temp_file("$maildir/tmp") or return undef;

[Improve upload.cgi.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912230953
 - check if patch is valid before sending
 - use sendmail to send patches or drop to maildir
] hunk ./tools/upload.cgi 4
-use Fcntl;
+use File::Temp qw/ tempfile /;
hunk ./tools/upload.cgi 7
-# it simply takes patches and places them in a Maildir style
-# mailbox.
+# it simply takes patches and sends them using sendmail or
+# places them in a Maildir style mailbox.
+
+my $tmp_dir;        # temporary directory, when placing patches to maildir
+                    # files are linked from $tmp_dir to $maildir
+$tmp_dir = "/tmp";
+
+my $target_email;   # target email addresses
+$target_email = 'dikk';
+
+my $target_repo;    # target repository for patch testing
+$target_repo = "/home/dikk/projects/darcs/unstable";
+
+my $sendmail_cmd;   # command to send patches with
+$sendmail_cmd = "/usr/sbin/sendmail $target_email";
+
+my $maildir;        # maildir to put patches to, replace sendmail
+#$maildir = "/tmp/maildir";
+
+my $patch_test_cmd; # command to test patches with
+$patch_test_cmd = "darcs apply --dry-run --repodir '$target_repo'";
hunk ./tools/upload.cgi 29
-# set this to the maildir you wish patches to be sent to.
-my $maildir = "/tmp/maildir";
hunk ./tools/upload.cgi 47
-    my $m = start_message($maildir) or error_page("could not open maildir: $maildir");
+    my $m = start_message() or error_page("could not create temporary file");
hunk ./tools/upload.cgi 56
+    unlink("$m->{filename}");
hunk ./tools/upload.cgi 66
-sub temp_file {
-    my ($temp_dir) = @_;
-    my $base_name = sprintf("patch-%d-%d-0000", $temp_dir, $$, time());
-    local *FH;
+sub maildir_file {
+    my ($tmp_file) = @_;
+    my $base_name = sprintf("patch-%d-%d-0000", $$, time());
hunk ./tools/upload.cgi 70
-    until (defined(fileno(FH)) || $count++ > 100) {
+    until (link("$tmp_file", "$maildir/$base_name")) {
hunk ./tools/upload.cgi 72
-        sysopen(FH, "$temp_dir/$base_name", O_WRONLY|O_EXCL|O_CREAT);
+        return undef if $count++ > 100;
hunk ./tools/upload.cgi 74
-    defined(fileno(FH)) ? return (*FH, $base_name) : return ();
+    return "$maildir/$base_name";
hunk ./tools/upload.cgi 78
-    my ($maildir) = @_;
-    my ($fh, $fname) = temp_file("$maildir/tmp") or return undef;
-    return { maildir => $maildir, fh => $fh, filename => $fname };
+    my ($fh, $fname) = tempfile("$tmp_dir/dpatch".'X'x8) or return undef;
+    return { fh => $fh, filename => $fname };
hunk ./tools/upload.cgi 85
-    link "$m->{maildir}/tmp/$m->{filename}", "$m->{maildir}/new/$m->{filename}" or return "$@: $m->{filename} - could not link to new";
-    unlink "$m->{maildir}/tmp/$m->{filename}";
+
+    system("$patch_test_cmd '$m->{filename}' >/dev/null 2>/dev/null") == 0 or
+        return "Patch is not valid: '$patch_test_cmd' failed";
+
+    if ($maildir) {
+        maildir_file("$m->{filename}") or
+            return "$!: Could not create a new file in maildir";
+    } else {
+        system("$sendmail_cmd < '$m->{filename}'") == 0 or
+            return "$!: Could not send mail";
+    }
+

Context:

[refactor Darcs.URL to eliminate use of Regexes.
David Roundy <[EMAIL PROTECTED]>**20080912173611
 The algorithms here are not tricky, and I find this easier to read.
] 
[change is_file to return false on [EMAIL PROTECTED]:
David Roundy <[EMAIL PROTECTED]>**20080912173501] 
[clean up whitespace.
David Roundy <[EMAIL PROTECTED]>**20080912150248] 
[fix manual for optional arguments.
David Roundy <[EMAIL PROTECTED]>**20080912150231] 
[clean up whitespace.
David Roundy <[EMAIL PROTECTED]>**20080912145708] 
[add test for new --output-auto-name feature.
David Roundy <[EMAIL PROTECTED]>**20080912145648] 
[Spaces in Darcs.Commands.Send module.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912122223] 
[Make '--output-auto-name' accept optional directory argument.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912120516] 
[Add DarcsOptAbsPathOption for options with optional path argument.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912112458] 
[Refactor Darcs.Repository.Prefs.getCaches.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912055204] 
[Print warning when '--http-pipelining' option is used, but darcs is compiled without HTTP pipelining support.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912054253] 
[Do not download URL we have speculated before.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912053236] 
[Spaces and parentheses in URL module.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080912053000] 
[Coding style in Darcs.Arguments.network_options.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080911140710] 
[Resolve issue1054: --no-cache option to ignore patch caches.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080911140233] 
[Remove unused variable from configure.ac.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080911132107] 
[Comment in configure.ac.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080911115840] 
[Indentation fixes in configure.ac.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080911115117] 
[Formating and minor refactoring in URL.urlThread.
Dmitry Kurochkin <[EMAIL PROTECTED]>**20080910061227] 
[insecure printfs - fix the two that I can currently hit
Steve Cotton <[EMAIL PROTECTED]>**20080910230659] 
[TAG this version works.
David Roundy <[EMAIL PROTECTED]>**20080910212908] 
Patch bundle hash:
c2e3c4d2aa874ab4cfb1a89eb611ce1ebcd49e37
_______________________________________________
darcs-users mailing list
darcs-users@darcs.net
http://lists.osuosl.org/mailman/listinfo/darcs-users

Reply via email to