Merge branch 'master' of git.sv.gnu.org:/srv/git/oddmuse

This commit is contained in:
Alex Schroeder
2012-05-18 10:29:25 +02:00
5 changed files with 224 additions and 8132 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*~
/current.pl
\#*\#
/test-data

8126
ChangeLog

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,23 @@ body {
font-size:12pt;
}
}
/* iPhone */
@media only screen and (max-device-width: 480px) {
body { font-size: 200%; }
}
/* iPad */
@media only screen and (min-device-width: 481px) and (max-device-width: 900px) {
body { font-size: 150%; }
textarea,input { font-size: 100%; }
img { max-width: 550px !important; }
}
div.browse {
min-height: 3em;
}
@@ -41,6 +58,14 @@ div.commentshown {
}
div.commenthidden { display:none; }
div.commentshown { display:block; }
/* comment pages with username, homepage, and email subscription */
.comment span { display: block; }
.comment span label {
display: inline-block; width: 10em;
}
input#mail, input#homepage, input#username {
display: inline-block; width: 20em;
}
h1 {
font-weight: bold;
@@ -63,9 +88,10 @@ h2 {
font-weight: bold;
color: white;
background-color: #000;
width: 98%;
/* width: 98%; */
font-size: 110%;
padding: 0.2em;
clear: both;
}
a:link {
font-weight: bold;
@@ -89,21 +115,47 @@ div.image { display: inline; margin: 1em; font-size: 90%; text-align: center; }
.right { float: right; margin-left: 1em; }
div.right .right { float: none; }
div.left .left { float: none; }
.caption { padding: 0 1em; }
.license { font-size: small; }
.aside {
font-size: small;
width: 30%;
float: right;
margin-left: 1em;
margin-bottom: 1em;
padding-left: 1em;
}
.aside img.smiley { height: 1em; }
.narrow {
width: 70%;
}
a img { border: 1px solid #333; }
.fit img { width: 80%; text-align: center; margin: 2em 8%; }
.half img { width: 50%; height: 50%; text-align: center; margin: 2em 8%; }
.noborder img { border: none; }
.twenty img { max-width: 20em; }
em.underline { font-weight: bold; }
.bar a { padding-right: 1em; }
textarea { width:100%; }
div.edit { padding-right: 1em; }
img.logo { float: right; clear: right; border-style:none; }
img.logo {
float: right;
clear: right;
border-style:none;
margin-left: 1em;
margin-bottom: 1ex;
border: 1px solid black;
}
div.diff { padding-left:5%; padding-right:5%; }
div.old { background-color:#FFFFAF; }
div.new { background-color:#CFFFCF; }
div.message { background-color:#FEE; }
/* div.message { background-color:#FEE; } */
div.message {
background-color: inherit;
font-size: smaller;
}
table.history { border-style:none; }
td.history { border-style:none; }
span.result { font-size:larger; }
@@ -132,6 +184,10 @@ table.user {
border-top: 1px solid black;
border-bottom: 1px solid black;
}
div.aside table.user {
margin: 1em 0;
padding: 0;
}
table.user td, table.user th {
border-style: none;
padding:5px 10px;
@@ -153,6 +209,12 @@ table.user td.mark { background-color:yellow; }
}
}
/* Help */
.edit table {
font-size: small;
}
/* Calendar */
div.month { margin:0; padding:0; font-size:x-small; float:right; }
div.content div.month { float:none; }
@@ -164,7 +226,7 @@ div.month span.title a { font: inherit; }
div.month a.local { font-weight: bold; }
div.month a.local:link { color: #562; }
div.month a.local:visited { color: #542; }
div.month a.today { font-weight: bold; color: #fff; }
div.month a.today { background-color: #faa; }
div.month span.title a.local { font-weight: normal; color: #842; }
@media print {
div.month { display: none; }

152
imap2wiki Executable file
View File

@@ -0,0 +1,152 @@
#!/usr/bin/perl -w
#
# Copyright (C) 2012 Alex Schroeder <alex@gnu.org>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
use Getopt::Std;
use LWP::UserAgent;
use Net::IMAP::Simple;
use Email::Simple;
use Email::MIME;
use IO::Socket::SSL; # fail unless this is available
my $usage = "Usage:\n"
. " imap2wiki TARGET SERVER PORT FROM TO MAIL_USER MAIL_PASSWORD \\\n"
. " MAIL_USER MAIL_PASSWORD WIKI_USER [WIKI_PASSWORD]\n\n"
. "TARGET is the base URL for the wiki.\n"
. "SERVER is the IMAP server you are checking.\n"
. "PORT is the port you are using.\n"
. " (We assume that you must use SSL.)\n"
. "FROM is sender you are looking for.\n"
. "TO is recipient you are looking for.\n"
. "MAIL_USER is the username to connect to the mail server.\n"
. "MAIL_PASSWORD is the password to use for the mail server.\n"
. "WIKI_USER is the username to use for the edit.\n"
. "WIKI_PASSWORD is the password to use if required.\n"
. "Example:\n"
. " imap2wiki http://www.emacswiki.org/cgi-bin/test imap.gmail.com 993 \\\n"
. " kensanata\@gmail.com kensanata+post\@gmail.com \\\n"
. " kensanata\@gmail.com '*secret*' \\\n"
. " Alex test\n\n";
sub UrlEncode {
my $str = shift;
return '' unless $str;
my @letters = split(//, $str);
my @safe = ('a' .. 'z', 'A' .. 'Z', '0' .. '9', '-', '_', '.', '!',
'~', '*', "'", '(', ')', '#');
foreach my $letter (@letters) {
my $pattern = quotemeta($letter);
if (not grep(/$pattern/, @safe)) {
$letter = sprintf("%%%02x", ord($letter));
}
}
return join('', @letters);
}
sub GetRaw {
my ($uri) = @_;
my $ua = LWP::UserAgent->new;
my $response = $ua->get($uri);
return $response->content if $response->is_success;
}
sub PostRaw {
my ($uri, $id, $data, $user, $pwd) = @_;
my $ua = LWP::UserAgent->new;
my $summary;
if ($data =~ /^#FILE (\S+) ?(\S+)?\n/) {
$summary = 'file upload';
}
my $response = $ua->post($uri, {title=>$id, text=>$data, raw=>1,
summary=>$summary,
username=>$user, pwd=>$pwd});
warn "POST $id failed: " . $response->status_line . "\n"
unless $response->is_success;
return $response->is_success;
}
sub post {
my ($target, $page, $data, $user, $pwd) = @_;
$page =~ s/ /_/g;
$page = UrlEncode ($page);
return PostRaw($target, $page, $data, $user, $pwd);
}
sub main {
my ($target, $server, $port, $from, $to,
$mail_user, $mail_pwd, $wiki_user, $wiki_pwd) = @ARGV;
# all parameters except the wiki password are mandatory
for my $arg ($target, $server, $port, $from, $to,
$mail_user, $mail_pwd, $wiki_user) {
die $usage unless $arg;
}
my $imap = Net::IMAP::Simple->new($server, port=>$port, use_ssl=>1 )
or die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n";
if (not $imap->login($mail_user, $mail_pwd)) {
print STDERR "Login failed: " . $imap->errstr . "\n";
exit(64);
}
my %result;
my $rfrom = quotemeta($from);
my $rto = quotemeta($to);
# go through the inbox and look for appropriate mails
my $num = $imap->select('INBOX');
for (my $i = 1; $i <= $num; $i++) {
# looking at headers only
my $email = Email::Simple->new(join '', @{ $imap->top($i) } );
if ($email->header("From") =~ /$rfrom/io
and $email->header("To") =~ /$rto/io) {
my $subject = $email->header('Subject');
my $n = 1;
# fetch the body and parse the MIME stuff
$email = Email::MIME->new(join '', @{ $imap->get($i) } );
$email->walk_parts(sub {
my ($part) = @_;
return if $part->subparts; # multipart
my ($pagename, $data);
warn $part->content_type;
if ($part->content_type =~ m[text/plain]i) {
($pagename, $data) = ($subject, $part->body);
} elsif ($part->content_type =~ m!(image/[a-z]+)!i) {
($pagename, $data) = ($subject . " " . $n++,
"#FILE " . $1 . "\n" . $part->body_raw);
}
if ($pagename and $data) {
warn "Posting $pagename\n";
post($target, $pagename, $data, $wiki_user, $wiki_pwd)
|| die "Posting aborted, INBOX not expunged\n";
}
} );
# mark as deleted
$imap->delete($i);
}
}
# expunge messages that are marked for deletion
$imap->quit;
}
main();

View File

@@ -381,7 +381,7 @@ sub SetParam {
}
sub InitLinkPatterns {
my ($UpperLetter, $LowerLetter, $AnyLetter, $WikiWord, $QDelim);
my ($WikiWord, $QDelim);
$QDelim = '(?:"")?'; # Optional quote delimiter (removed from the output)
$WikiWord = '[A-Z]+[a-z\x80-\xff]+[A-Z][A-Za-z\x80-\xff]*';
$LinkPattern = "($WikiWord)$QDelim";
@@ -2717,7 +2717,7 @@ sub GetKeptRevision { # Call after OpenPage
}
sub GetPageFile {
my ($id, $revision) = @_;
my ($id) = @_;
return $PageDir . '/' . GetPageDirectory($id) . "/$id.pg";
}