mirror of
https://github.com/imapsync/imapsync.git
synced 2025-07-30 22:06:07 +02:00
1.504
This commit is contained in:
parent
495d5a9526
commit
c08a56e486
277 changed files with 692 additions and 10803 deletions
48
W/learn/adjust_time.pl
Normal file
48
W/learn/adjust_time.pl
Normal file
|
@ -0,0 +1,48 @@
|
|||
#! /usr/bin/perl -w
|
||||
#
|
||||
# Author : Jean-Yves Boisiaud
|
||||
#
|
||||
# Outlook (IMAP) manages mail dates from the creation date of the mail
|
||||
# instead of the content of the field 'Date:', included into the mail.
|
||||
# This script modifies the mtime of the mails, according to the 'Date:' field
|
||||
# value.
|
||||
# Before running the script, you have to build a list of the mail files.
|
||||
# For example, with the MailDir format, the file has been built whith :
|
||||
# find /var/lib/vmail -type f -a -name '[0-9]*' > /tmp/toto
|
||||
# Depending on the quality of the 'Date:' field, some mtime modification fails.
|
||||
# You have to correct it manually.
|
||||
# I ran it on 18733 mails, and 45 failed.
|
||||
|
||||
use strict;
|
||||
|
||||
my @a;
|
||||
my $f;
|
||||
my @b;
|
||||
my @date;
|
||||
my $d;
|
||||
my @r;
|
||||
my $s;
|
||||
|
||||
open(F, "</tmp/toto") or die "can't open toto";
|
||||
@a = <F>;
|
||||
chomp @a;
|
||||
|
||||
foreach $f (@a)
|
||||
{
|
||||
open(F1, "<$f") or die "can't open $f";
|
||||
@b = <F1>;
|
||||
chomp @b;
|
||||
close F1;
|
||||
@date = grep /^Date: /, @b;
|
||||
next if scalar @date <= 0;
|
||||
$d = $date[0];
|
||||
$d =~ s/Date: (.*)$/$1/i;
|
||||
print "$d\n";
|
||||
@r = `/usr/bin/touch -md '$d' '$f' 2>&1`;
|
||||
print "$f\n";
|
||||
foreach $d (@r)
|
||||
{
|
||||
print "$d\n"
|
||||
}
|
||||
}
|
||||
|
53
W/learn/append
Executable file
53
W/learn/append
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use English;
|
||||
use Mail::IMAPClient;
|
||||
|
||||
my $rcs = '$Id: append,v 1.1 2011/07/14 16:49:02 gilles Exp gilles $ ';
|
||||
|
||||
$ARGV[3] or die "usage: $0 host user password folder uid\n";
|
||||
|
||||
my $host = $ARGV[0];
|
||||
my $user = $ARGV[1];
|
||||
my $password = $ARGV[2];
|
||||
my $folder = $ARGV[3];
|
||||
my $uid = $ARGV[4];
|
||||
|
||||
my $imap = Mail::IMAPClient->new();
|
||||
$imap->Debug(1);
|
||||
$imap->Server($host);
|
||||
$imap->connect() or die;
|
||||
$imap->User($user);
|
||||
$imap->Password($password);
|
||||
$imap->login() or die;
|
||||
$imap->Uid(1);
|
||||
$imap->Peek(1);
|
||||
$imap->Clear(0);
|
||||
|
||||
#print map {"$_\n"} $imap->folders();
|
||||
|
||||
$imap->select($folder) or die;
|
||||
my @msgs = $imap->messages ;
|
||||
print "LIST: @msgs\n";
|
||||
|
||||
my $msgtext = "Subject: 9
|
||||
|
||||
??
|
||||
" ;
|
||||
|
||||
my $flags = '\Seen' ;
|
||||
my $date = "16-Mar-2011 11:07:11 +0000" ;
|
||||
|
||||
my $new_id_1b = $imap->append_string( $folder, $msgtext ) ;
|
||||
print "==== OK 1b $new_id_1b\n" if $new_id_1b ;
|
||||
$imap->noop ;
|
||||
@msgs = $imap->messages ;
|
||||
print "LIST: @msgs\n";#my $new_id_1 = $imap->append_string( $folder, $msgtext, $flags, $date ) ;
|
||||
#print "==== OK 1 $new_id_1\n" if $new_id_1 ;
|
||||
#my $new_id_2 = $imap->append_string( $folder, $msgtext, $flags, $date ) ;
|
||||
#print "==== OK 2 $new_id_2\n" if $new_id_2 ;
|
||||
|
||||
$imap->close();
|
||||
|
28
W/learn/date_manip
Executable file
28
W/learn/date_manip
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
|
||||
require Date::Manip;
|
||||
|
||||
Date::Manip->import(qw(ParseDate Date_Cmp UnixDate));
|
||||
|
||||
print "Date::Manip::VERSION $Date::Manip::VERSION\n";
|
||||
|
||||
foreach $date_inp ("21-Jan-2004 23:10:58 +0200", "21-Feb-2004 0:14:02 +0200",
|
||||
"15-Oct-2004 23:25:42 +0200", "19-Aug-2005 1:49:08 +0200") {
|
||||
$date_dm = ParseDate($date_inp);
|
||||
$date_un = UnixDate($date_dm, "%g");
|
||||
unless ($date_dm) {
|
||||
print "Error in date [$date_inp]\n";
|
||||
next;
|
||||
}
|
||||
print " $date_inp\n$date_un\n";
|
||||
|
||||
}
|
||||
|
||||
$date1 = ParseDate("21-Feb-2004 0:14:02 +0200");
|
||||
$date2 = ParseDate("21-Feb-2004 00:14:02 +0200");
|
||||
|
||||
print "cmp date1 $date1 date2 $date2 : ", Date_Cmp($date1,$date2), "\n";
|
||||
|
||||
print "UnixDate ", UnixDate($date1, "%g"), "\n";
|
||||
print "UnixDate ", UnixDate(undef, "%g"), "\n";
|
30
W/learn/delete
Executable file
30
W/learn/delete
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
use Mail::IMAPClient;
|
||||
|
||||
$ARGV[3] or die "usage: $0 host user password folder uid1 uid2 ...\n";
|
||||
|
||||
$host = $ARGV[0];
|
||||
$user = $ARGV[1];
|
||||
$password = $ARGV[2];
|
||||
$folder = $ARGV[3];
|
||||
|
||||
my $imap = Mail::IMAPClient->new();
|
||||
$imap->Debug(1);
|
||||
$imap->Server($host);
|
||||
$imap->connect() or die;
|
||||
$imap->User($user);
|
||||
$imap->Password($password);
|
||||
$imap->login() or die;
|
||||
$imap->Uid(1);
|
||||
$imap->Peek(1);
|
||||
$imap->select($folder) or die;
|
||||
|
||||
foreach $uid (@ARGV[4..$#ARGV]) {
|
||||
print "deleting $uid\n";
|
||||
$imap->delete_message($uid);
|
||||
$imap->expunge();
|
||||
}
|
||||
$imap->close();
|
||||
|
||||
|
54
W/learn/fetch_with_size
Executable file
54
W/learn/fetch_with_size
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use English;
|
||||
use Mail::IMAPClient;
|
||||
|
||||
$ARGV[3] or die "usage: $0 host user password folder uid\n";
|
||||
|
||||
my $host = $ARGV[0];
|
||||
my $user = $ARGV[1];
|
||||
my $password = $ARGV[2];
|
||||
my $folder = $ARGV[3];
|
||||
my $uid = $ARGV[4];
|
||||
|
||||
my $imap = Mail::IMAPClient->new();
|
||||
$imap->Debug(0);
|
||||
$imap->Server($host);
|
||||
$imap->connect() or die;
|
||||
$imap->User($user);
|
||||
$imap->Password($password);
|
||||
$imap->login() or die;
|
||||
$imap->Uid(1);
|
||||
$imap->Peek(1);
|
||||
$imap->Clear(1);
|
||||
|
||||
#print map {"$_\n"} $imap->folders();
|
||||
|
||||
$imap->select($folder) or die;
|
||||
my @msgs = $imap->messages or die "Could not messages: $@\n";
|
||||
print "@msgs\n";
|
||||
foreach my $msg (@msgs) {
|
||||
$imap->fetch($msg, "BODY.PEEK[TEXT]<0.3000>");
|
||||
my $text = $imap->_transaction_literals;
|
||||
print '#' x 72, " $msg TEXT = \n$text\n";
|
||||
my $part = $imap->bodypart_string($msg, '', 3000, 0);
|
||||
print '#' x 72, " $msg PART = \n$part\n";
|
||||
}
|
||||
$imap->close();
|
||||
|
||||
|
||||
package Mail::IMAPClient;
|
||||
|
||||
sub _transaction_literals() {
|
||||
my $self = shift;
|
||||
my $string = "";
|
||||
|
||||
foreach my $result (@{$self->{"History"}{$self->Transaction}}) {
|
||||
$string .= $result->[DATA]
|
||||
if defined($result) and $self->_is_literal($result) ;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
14
W/learn/file_spec
Executable file
14
W/learn/file_spec
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Spec;
|
||||
|
||||
|
||||
my $tmpdir = File::Spec->tmpdir();
|
||||
print "$tmpdir\n";
|
||||
|
||||
|
||||
my $cachedir = File::Spec->catdir($tmpdir, 'host1', 'user1', 'host2', 'user2');
|
||||
print "$cachedir\n";
|
27
W/learn/file_string
Normal file
27
W/learn/file_string
Normal file
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
|
||||
|
||||
sub file_to_string {
|
||||
my($file) = @_;
|
||||
my @string;
|
||||
open FILE, $file or die("$! $file");
|
||||
@string = <FILE>;
|
||||
close FILE;
|
||||
return join("", @string);
|
||||
}
|
||||
|
||||
use Fcntl;
|
||||
sub string_to_file {
|
||||
my($string, $file) = @_;
|
||||
sysopen(FILE, $file,O_WRONLY|O_TRUNC|O_CREAT, 0600) or die("$! $file");
|
||||
print FILE $string;
|
||||
close FILE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
string_to_file("blabla $$ \n", "/tmp/imapsync_t01");
|
||||
print file_to_string("/tmp/imapsync_t01");
|
||||
#unlink("/tmp/imapsync_t01");
|
6
W/learn/hugemigr
Executable file
6
W/learn/hugemigr
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
{ while IFS=';' read u1 p1 u2 p2; do
|
||||
imapsync --user1 "$u1" --password1 "$p1" --user2 "$u2" --password2 "$p2" ...
|
||||
done ; } < file.csv
|
||||
|
12
W/learn/imapbyhand
Normal file
12
W/learn/imapbyhand
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
# How to remove a message by hand.
|
||||
telnet imap.truc.com 143
|
||||
|
||||
a01 CAPABILITY
|
||||
a02 LOGIN toto zorglub
|
||||
a43 SELECT INBOX
|
||||
a54 UID STORE 60010:60010 +FLAGS (\DELETED)
|
||||
a64 STORE 1:1 +FLAGS (\DELETED)
|
||||
a75 EXPUNGE
|
||||
a86 LOGOUT
|
||||
|
7
W/learn/imapclient3xx_isUnconnected
Normal file
7
W/learn/imapclient3xx_isUnconnected
Normal file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use Mail::IMAPClient;
|
||||
|
||||
print "$Mail::IMAPClient::VERSION\n";
|
||||
my $imap = Mail::IMAPClient->new();
|
||||
$imap->IsUnconnected();
|
23
W/learn/imapclient3xx_skeleton_test
Normal file
23
W/learn/imapclient3xx_skeleton_test
Normal file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
use Mail::IMAPClient;
|
||||
|
||||
$ARGV[3] or die "usage: $0 host user password folder\n";
|
||||
|
||||
$host = $ARGV[0];
|
||||
$user = $ARGV[1];
|
||||
$password = $ARGV[2];
|
||||
$folder = $ARGV[3];
|
||||
|
||||
my $imap = Mail::IMAPClient->new();
|
||||
$imap->Debug(1);
|
||||
$imap->Server($host);
|
||||
$imap->connect() or die;
|
||||
$imap->IsUnconnected();
|
||||
$imap->User($user);
|
||||
$imap->Password($password);
|
||||
$imap->login() or die;
|
||||
$imap->Uid(1);
|
||||
$imap->Peek(1);
|
||||
$imap->select($folder) or die;
|
||||
$imap->logout();
|
30
W/learn/imapclient3xx_ssl
Executable file
30
W/learn/imapclient3xx_ssl
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
use Mail::IMAPClient;
|
||||
use IO::Socket::SSL;
|
||||
|
||||
$ARGV[3] or die "usage: $0 host user password folder\n";
|
||||
|
||||
$host = $ARGV[0];
|
||||
$user = $ARGV[1];
|
||||
$password = $ARGV[2];
|
||||
$folder = $ARGV[3];
|
||||
|
||||
my $imap = Mail::IMAPClient->new();
|
||||
my $ssl = IO::Socket::SSL->new(
|
||||
Proto => 'tcp',
|
||||
PeerAddr => $host,
|
||||
PeerPort => 993, # IMAP over SSL standard port
|
||||
);
|
||||
|
||||
$imap->Debug(1);
|
||||
#$imap->Server($host);
|
||||
$imap->Socket($ssl);
|
||||
#$imap->connect() or die;
|
||||
$imap->User($user);
|
||||
$imap->Password($password);
|
||||
$imap->login() or die;
|
||||
$imap->Uid(1);
|
||||
$imap->Peek(1);
|
||||
$imap->select($folder) or die;
|
||||
$imap->close();
|
81
W/learn/imapclient_tls
Executable file
81
W/learn/imapclient_tls
Executable file
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
use Mail::IMAPClient;
|
||||
use IO::Socket::SSL qw(debug1 debug2 debug3) ;
|
||||
|
||||
$ARGV[3] or die "usage: $0 host user password folder\n";
|
||||
|
||||
$host = $ARGV[0];
|
||||
$user = $ARGV[1];
|
||||
$password = $ARGV[2];
|
||||
$folder = $ARGV[3];
|
||||
|
||||
my $imap = Mail::IMAPClient->new();
|
||||
|
||||
|
||||
my $socket = IO::Socket::INET->new(
|
||||
Proto => 'tcp',
|
||||
PeerAddr => $host,
|
||||
PeerPort => 143,
|
||||
);
|
||||
|
||||
$socket->autoflush(1);
|
||||
|
||||
my $banner = $socket->getline();
|
||||
unless ($banner =~ /^\* OK \[CAPABILITY.*STARTTLS.*\]/) {
|
||||
die "No STARTTLS capability: $banner";
|
||||
}
|
||||
|
||||
|
||||
print $socket "STARTTLS\015\012";
|
||||
my $txt = $socket->getline();
|
||||
unless($txt =~ /^STARTTLS OK/){
|
||||
die "Invalid response for STARTTLS: $txt\n";
|
||||
}
|
||||
|
||||
my $result = IO::Socket::SSL->start_SSL($socket,
|
||||
{
|
||||
SSL_startHandshake => 1,
|
||||
SSL_version => "TLSv1",
|
||||
SSL_verify_depth => 1,
|
||||
}
|
||||
);
|
||||
|
||||
print "start_SSL return $result\n";
|
||||
|
||||
unless ($result){
|
||||
|
||||
die "Couldn't start TLS: ".IO::Socket::SSL::errstr()."\n";
|
||||
}
|
||||
|
||||
if (ref($socket) ne "IO::Socket::SSL") {
|
||||
die "Socket has not been converted to SSL";
|
||||
}else{
|
||||
print "Socket has been converted to SSL\n";
|
||||
}
|
||||
$imap->State(Mail::IMAPClient::Connected);
|
||||
|
||||
|
||||
$imap->Debug(1);
|
||||
print "Socket\n";
|
||||
$imap->RawSocket($socket);
|
||||
#$imap->Socket($socket);
|
||||
|
||||
print $socket "a02 CAPABILITY\n";
|
||||
print "getline\n";
|
||||
$txt = $socket->getline();
|
||||
|
||||
print "getline : $txt \n";
|
||||
|
||||
|
||||
#$imap->connect() or die;
|
||||
print "User\n";
|
||||
$imap->User($user);
|
||||
$imap->Password($password);
|
||||
print "login\n";
|
||||
|
||||
$imap->login() or die;
|
||||
$imap->Uid(1);
|
||||
$imap->Peek(1);
|
||||
$imap->select($folder) or die;
|
||||
$imap->close();
|
115
W/learn/io_socket_get
Executable file
115
W/learn/io_socket_get
Executable file
|
@ -0,0 +1,115 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use IO::Socket;
|
||||
use English ;
|
||||
use POSIX qw(uname SIGALRM);
|
||||
use lib ( '../Mail-IMAPClient-3.25/lib' ) ;
|
||||
use Mail::IMAPClient;
|
||||
|
||||
sub last_release {
|
||||
my $host = shift || 'linux-france.org' ;
|
||||
my $sock = new IO::Socket::INET (
|
||||
PeerAddr => $host,
|
||||
PeerPort => '80',
|
||||
Proto => 'tcp');
|
||||
return('unknown') if not $sock;
|
||||
print $sock
|
||||
"GET /prj/imapsync/VERSION HTTP/1.0\n",
|
||||
"Host: www.linux-france.org\n\n";
|
||||
my @line = <$sock>;
|
||||
close($sock);
|
||||
my $last_release = $line[-1];
|
||||
chomp($last_release);
|
||||
return($last_release);
|
||||
}
|
||||
|
||||
sub not_long {
|
||||
|
||||
my ($func) = @_;
|
||||
my $val;
|
||||
eval {
|
||||
local $SIG{ALRM} = sub { die "alarm\n" };
|
||||
alarm 3;
|
||||
#print $func, "\n";
|
||||
{
|
||||
no strict "refs";
|
||||
$val = &$func();
|
||||
}
|
||||
alarm 0;
|
||||
};
|
||||
if ($@) {
|
||||
# timed out
|
||||
return('unknown') unless $@ eq "alarm\n"; # propagate unexpected errors
|
||||
|
||||
}else {
|
||||
# didn't
|
||||
return($val);
|
||||
}
|
||||
}
|
||||
|
||||
sub not_long2 {
|
||||
#print "Entering not_long\n";
|
||||
my ( $func ) = shift ;
|
||||
my ( @argv ) = @_ ;
|
||||
my $val ;
|
||||
|
||||
# Doesn't work with gethostbyname (see perlipc)
|
||||
#local $SIG{ALRM} = sub { die "alarm\n" };
|
||||
|
||||
if ('MSWin32' eq $OSNAME) {
|
||||
local $SIG{ALRM} = sub { die "alarm\n" };
|
||||
}else{
|
||||
|
||||
POSIX::sigaction(SIGALRM,
|
||||
POSIX::SigAction->new(sub { die "alarm" }))
|
||||
or warn "Error setting SIGALRM handler: $!\n";
|
||||
}
|
||||
|
||||
eval {
|
||||
|
||||
alarm(3);
|
||||
print "$func @argv", "\n";
|
||||
{
|
||||
no strict "refs";
|
||||
#print "Calling $func\n";
|
||||
$val = &$func( @argv ) ;
|
||||
#print "End of $func\n";
|
||||
}
|
||||
alarm(0);
|
||||
};
|
||||
if ( $@ ) {
|
||||
#print "$@";
|
||||
if ($@ =~ /alarm/) {
|
||||
# timed out
|
||||
return('timeout');
|
||||
}else{
|
||||
alarm(0);
|
||||
return('unknown'); # propagate unexpected errors
|
||||
}
|
||||
}else {
|
||||
# didn't
|
||||
return($val);
|
||||
}
|
||||
}
|
||||
|
||||
sub connect_test {
|
||||
my $host = 'localhost' ;
|
||||
|
||||
my $imap = Mail::IMAPClient->new( ) ;
|
||||
$imap->Debug( 1 ) ;
|
||||
$imap->Server( $host ) ;
|
||||
$imap->connect( ) or die ;
|
||||
$imap->IsUnconnected( ) ;
|
||||
$imap->logout( ) ;
|
||||
}
|
||||
|
||||
|
||||
#print last_release(), "\n" ;
|
||||
#print not_long('last_release'), "\n" ;
|
||||
connect_test( ) ;
|
||||
print not_long2( 'last_release', ), "\n" ;
|
||||
#print not_long2( 'last_release' ), "\n" ;
|
||||
|
||||
connect_test( ) ;
|
22
W/learn/memo
Normal file
22
W/learn/memo
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
|
||||
|
||||
loul Cyrus
|
||||
==========
|
||||
|
||||
|
||||
vi /var/lib/cyrus/mailboxes
|
||||
|
||||
ls /var/spool/cyrus/mail/user/tata/
|
||||
|
||||
|
||||
plume courier
|
||||
=============
|
||||
|
||||
vi /etc/courier/userdb
|
||||
|
||||
ls -a /home/vmail/tata/
|
||||
|
||||
userdbpw -hmac-md5 | userdb tata@est.belle set hmac-md5pw
|
||||
makeuserdb
|
||||
|
57
W/learn/memory_consumption
Executable file
57
W/learn/memory_consumption
Executable file
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use English;
|
||||
use Mail::IMAPClient;
|
||||
|
||||
$ARGV[3] or die "usage: $0 host user password folder\n";
|
||||
|
||||
my $host = $ARGV[0];
|
||||
my $user = $ARGV[1];
|
||||
my $password = $ARGV[2];
|
||||
my $folder = $ARGV[3];
|
||||
|
||||
my $imap = Mail::IMAPClient->new();
|
||||
$imap->Debug(0);
|
||||
$imap->Server($host);
|
||||
$imap->connect() or die;
|
||||
$imap->User($user);
|
||||
$imap->Password($password);
|
||||
$imap->login() or die;
|
||||
$imap->Uid(1);
|
||||
$imap->Peek(1);
|
||||
$imap->Clear(1);
|
||||
|
||||
#print map {"$_\n"} $imap->folders();
|
||||
|
||||
$imap->select($folder) or die;
|
||||
my @msgs = $imap->messages or die "Could not messages: $@\n";
|
||||
print "@msgs\n";
|
||||
print memory_consumption();
|
||||
foreach my $msg (@msgs) {
|
||||
my $size = $imap->size($msg);
|
||||
print "message size of $msg = $size bytes\n";
|
||||
my $string = $imap->message_string($msg);
|
||||
print memory_consumption();
|
||||
$imap->append('INBOX.Trash', $string);
|
||||
print memory_consumption();
|
||||
}
|
||||
$imap->close();
|
||||
print memory_consumption();
|
||||
|
||||
|
||||
sub memory_consumption {
|
||||
|
||||
my @PID = (@_) ? @_ : ($PROCESS_ID);
|
||||
my $val;
|
||||
|
||||
my ($package, $filename, $line, $subroutine) = caller(0);
|
||||
$val = "$package $filename line $line: ";
|
||||
my @ps = qx{ ps o vsz @PID };
|
||||
my $vsz = $ps[1];
|
||||
chomp($vsz);
|
||||
$val .= $vsz * 1024 . " bytes\n";
|
||||
#$val .= '-' x 80 . "\n";
|
||||
return($val);
|
||||
}
|
110
W/learn/message_string_raw
Executable file
110
W/learn/message_string_raw
Executable file
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use English;
|
||||
use Mail::IMAPClient;
|
||||
use Socket;
|
||||
|
||||
$ARGV[3] or die "usage: $0 host user password folder\n";
|
||||
|
||||
my $host = $ARGV[0];
|
||||
my $user = $ARGV[1];
|
||||
my $password = $ARGV[2];
|
||||
my $folder = $ARGV[3];
|
||||
|
||||
my $imap = Mail::IMAPClient->new();
|
||||
$imap->Debug(0);
|
||||
$imap->Server($host);
|
||||
$imap->connect() or die;
|
||||
$imap->User($user);
|
||||
$imap->Password($password);
|
||||
$imap->login() or die;
|
||||
$imap->Uid(1);
|
||||
$imap->Peek(1);
|
||||
$imap->Clear(1);
|
||||
|
||||
#print map {"$_\n"} $imap->folders();
|
||||
|
||||
$imap->select($folder) or die;
|
||||
my @msgs = $imap->messages or die "Could not messages: $@\n";
|
||||
print "@msgs\n";
|
||||
print memory_consumption_ratio(), "\n";
|
||||
|
||||
my $size_max = 0;
|
||||
foreach my $msg (@msgs) {
|
||||
my $size = $imap->size($msg);
|
||||
$size_max = ($size_max > $size) ? $size_max : $size;
|
||||
print "message size of $msg = $size bytes\n";
|
||||
my $string_raw = $imap->message_string_raw($msg);
|
||||
print "ms raw: ", memory_consumption_ratio($size_max), "\n";
|
||||
my $string = $imap->message_string($msg);
|
||||
print "ms nor: ", memory_consumption_ratio($size_max), "\n";
|
||||
print "NOT EQUAL\n" if ($string_raw ne $string);
|
||||
#print substr($string_raw, 0, 80), "]\n";
|
||||
#print substr($string_raw, -80, 80), "]\n";
|
||||
$imap->append('INBOX.Trash', $string_raw);
|
||||
$imap->append('INBOX.Trash', $string);
|
||||
}
|
||||
$imap->close();
|
||||
print "ap nor: ", memory_consumption_ratio($size_max), "\n";
|
||||
|
||||
|
||||
sub memory_consumption_of_pid {
|
||||
|
||||
my @PID = (@_) ? @_ : ($PROCESS_ID);
|
||||
my $val;
|
||||
|
||||
my @ps = qx{ ps o vsz @PID };
|
||||
shift @ps;
|
||||
chomp @ps;
|
||||
my @val = map { $_ * 1024 } @ps;
|
||||
return(@val);
|
||||
}
|
||||
|
||||
sub memory_consumption_ratio {
|
||||
|
||||
my ($base) = @_;
|
||||
$base ||= 1;
|
||||
my ($consu) = memory_consumption_of_pid();
|
||||
return($consu / $base);
|
||||
}
|
||||
|
||||
package Mail::IMAPClient;
|
||||
|
||||
sub message_string_raw {
|
||||
|
||||
my $self = shift;
|
||||
my ($msg) = @_;
|
||||
my $sock = $self->{Socket};
|
||||
print "Socket:[$sock]\n";
|
||||
my $count = $self->Count($self->Count+1);
|
||||
|
||||
print $sock "$count UID FETCH 1 BODY.PEEK[]\r\n";
|
||||
my $buf;
|
||||
my $line;
|
||||
CORE::select( undef, undef, undef, 0.025 );
|
||||
my $expected_size;
|
||||
|
||||
local $/ = "\r\n";
|
||||
$line = <$sock>;
|
||||
print $line;
|
||||
|
||||
if ( $line =~ m/.*{(\d+)\}\r\n/o ) {
|
||||
$expected_size = $1;
|
||||
print "\nEXPECT $expected_size\n";
|
||||
}
|
||||
|
||||
#local $/;
|
||||
while ($buf .= <$sock> and (length $buf <= $expected_size)){
|
||||
#print length $buf, "\n";
|
||||
#CORE::select( undef, undef, undef, 0.025 );
|
||||
}
|
||||
$line = <$sock>;
|
||||
print $line;
|
||||
if ( $line =~ m/$count OK FETCH.*\r\n/o ) {
|
||||
return(substr($buf, 0, $expected_size))
|
||||
}else{
|
||||
return(undef);
|
||||
}
|
||||
}
|
209
W/learn/message_string_raw_pb
Executable file
209
W/learn/message_string_raw_pb
Executable file
|
@ -0,0 +1,209 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use English;
|
||||
use Mail::IMAPClient;
|
||||
use Socket;
|
||||
|
||||
$ARGV[3] or die "usage: $0 host user password folder\n";
|
||||
|
||||
my $host = $ARGV[0];
|
||||
my $user = $ARGV[1];
|
||||
my $password = $ARGV[2];
|
||||
my $folder = $ARGV[3];
|
||||
|
||||
my $imap = Mail::IMAPClient->new();
|
||||
$imap->Debug(0);
|
||||
$imap->Server($host);
|
||||
$imap->connect() or die;
|
||||
$imap->User($user);
|
||||
$imap->Password($password);
|
||||
$imap->login() or die;
|
||||
$imap->Uid(1);
|
||||
$imap->Peek(1);
|
||||
$imap->Clear(1);
|
||||
|
||||
#print map {"$_\n"} $imap->folders();
|
||||
|
||||
$imap->select($folder) or die;
|
||||
my @msgs = $imap->messages or die "Could not messages: $@\n";
|
||||
print "@msgs\n";
|
||||
print memory_consumption_ratio(), "\n";
|
||||
|
||||
my $size_max = 0;
|
||||
foreach my $msg (@msgs) {
|
||||
my $size = $imap->size($msg);
|
||||
$size_max = ($size_max > $size) ? $size_max : $size;
|
||||
print "message size of $msg = $size bytes\n";
|
||||
my $string_raw = $imap->message_string_raw($msg);
|
||||
print "ms raw: ", memory_consumption_ratio($size_max), "\n";
|
||||
|
||||
#$imap->append_string('INBOX.Trash', $string_raw);
|
||||
my $uid_raw = $imap->append_string_raw('INBOX.Trash', $string_raw);
|
||||
print "ap raw $uid_raw: ", memory_consumption_ratio($size_max), "\n";
|
||||
my $string = $imap->message_string($msg);
|
||||
print "ms nor: ", memory_consumption_ratio($size_max), "\n";
|
||||
print "NOT EQUAL\n" if ($string_raw ne $string);
|
||||
#print substr($string_raw, 0, 80), "]\n";
|
||||
#print substr($string_raw, -80, 80), "]\n";
|
||||
my $uid_nor = $imap->append_string('INBOX.Trash', $string_raw);
|
||||
print "ap nor $uid_nor: ", memory_consumption_ratio($size_max), "\n";
|
||||
$imap->select('INBOX.Trash') or die;
|
||||
$string_raw = $imap->message_string_raw($uid_raw);
|
||||
print "msraw $uid_raw D:", substr($string_raw, 0, 80), "]\n";
|
||||
print "msraw $uid_raw F:", substr($string_raw, -80, 80), "]\n";
|
||||
$string = $imap->message_string_raw($uid_nor);
|
||||
print "msraw $uid_nor D:", substr($string, 0, 80), "]\n";
|
||||
print "msraw $uid_nor F:", substr($string, -80, 80), "]\n";
|
||||
print "NOT EQUAL app\n" if ($string_raw ne $string);
|
||||
print "eq: ", memory_consumption_ratio($size_max), "\n";
|
||||
}
|
||||
$imap->close();
|
||||
|
||||
|
||||
sub memory_consumption_of_pid {
|
||||
|
||||
my @PID = (@_) ? @_ : ($PROCESS_ID);
|
||||
my $val;
|
||||
|
||||
my @ps = qx{ ps o vsz @PID };
|
||||
shift @ps;
|
||||
chomp @ps;
|
||||
my @val = map { $_ * 1024 } @ps;
|
||||
return(@val);
|
||||
}
|
||||
|
||||
sub memory_consumption_ratio {
|
||||
|
||||
my ($base) = @_;
|
||||
$base ||= 1;
|
||||
my ($consu) = memory_consumption_of_pid();
|
||||
return($consu / $base);
|
||||
}
|
||||
|
||||
package Mail::IMAPClient;
|
||||
use Errno qw(EAGAIN EPIPE ECONNRESET);
|
||||
|
||||
sub message_string_raw {
|
||||
|
||||
my $self = shift;
|
||||
my ($msg) = @_;
|
||||
my $sock = $self->{Socket};
|
||||
my $io_sel= IO::Select->new($sock);
|
||||
my $count = $self->Count($self->Count+1);
|
||||
|
||||
print "$count UID FETCH $msg BODY.PEEK[]\r\n";
|
||||
print $sock "$count UID FETCH $msg BODY.PEEK[]\r\n";
|
||||
my $buf;
|
||||
my $line;
|
||||
CORE::select( undef, undef, undef, 0.025 );
|
||||
my $expected_size;
|
||||
|
||||
local $/ = "\r\n";
|
||||
$line = <$sock>;
|
||||
print "msr <> [$line]";
|
||||
|
||||
if ( $line =~ m/.*{(\d+)\}\r\n/o ) {
|
||||
$expected_size = $1;
|
||||
print "\nEXPECT $expected_size\n";
|
||||
}
|
||||
|
||||
#local $/;
|
||||
while ($buf .= <$sock> and (length $buf <= $expected_size)){
|
||||
}
|
||||
CORE::select( undef, undef, undef, 0.025 );
|
||||
$line = <$sock>;
|
||||
print "[$line][$count OK FETCH]\n";
|
||||
if ( $line =~ m/$count OK FETCH/o ) {
|
||||
print "GOOD\n";
|
||||
return(substr($buf, 0, $expected_size))
|
||||
}else{
|
||||
print "BAD\n";
|
||||
return(undef);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub append_string_raw {
|
||||
my $self = shift;
|
||||
|
||||
my $folder = $self->Massage(shift);
|
||||
my ( $text, $flags, $date ) = @_;
|
||||
defined $text or $text = '';
|
||||
|
||||
my $sock = $self->{Socket};
|
||||
my $io_sel = IO::Select->new($sock);
|
||||
|
||||
my($count, $line);
|
||||
|
||||
if ( defined $flags ) {
|
||||
$flags =~ s/^\s+//g;
|
||||
$flags =~ s/\s+$//g;
|
||||
$flags = "($flags)" if $flags !~ /^\(.*\)$/;
|
||||
}
|
||||
|
||||
if ( defined $date ) {
|
||||
$date =~ s/^\s+//g;
|
||||
$date =~ s/\s+$//g;
|
||||
$date = qq("$date") if $date !~ /^"/;
|
||||
}
|
||||
|
||||
#$text =~ s/\r?\n/\r\n/og;
|
||||
|
||||
my $command =
|
||||
"APPEND $folder "
|
||||
. ( $flags ? "$flags " : "" )
|
||||
. ( $date ? "$date " : "" ) . "{"
|
||||
. length($text)
|
||||
. "}\r\n";
|
||||
|
||||
local $/ = "\r\n";
|
||||
|
||||
#print $command;
|
||||
|
||||
$count = $self->Count($self->Count+1);
|
||||
my $string = "$count ". $command . $text . "\r\n";
|
||||
$io_sel->can_write();
|
||||
$self->_send_bytes_2(\$string);
|
||||
$io_sel->can_read();
|
||||
$line = <$sock>;
|
||||
#print "APP 1 [$line]\n";
|
||||
|
||||
$io_sel->can_read();
|
||||
$line = <$sock>;
|
||||
print "APP 2 [$line]\n";
|
||||
|
||||
my $ret;
|
||||
# <tag> OK [APPENDUID <size> <uid>] APPEND completed
|
||||
if ($line =~ m{^$count\s+OK\s+\[APPENDUID\s+\d+\s+(\d+)\]}) {
|
||||
$ret = $1;
|
||||
}else{
|
||||
$ret = undef;
|
||||
}
|
||||
return($ret);
|
||||
}
|
||||
|
||||
sub _send_bytes_2 {
|
||||
my ( $self, $byteref ) = @_;
|
||||
my ( $total ) = ( 0 );
|
||||
|
||||
local $SIG{PIPE} = 'IGNORE'; # handle SIGPIPE as normal error
|
||||
|
||||
while ( $total < length $$byteref ) {
|
||||
my $written =
|
||||
syswrite( $self->Socket, $$byteref, length($$byteref) - $total,
|
||||
$total );
|
||||
|
||||
if ( defined $written ) {
|
||||
$total += $written;
|
||||
next;
|
||||
}
|
||||
|
||||
next if ( $! == EAGAIN ) ;
|
||||
|
||||
return undef; # no luck
|
||||
}
|
||||
$self->_debug("Sent $total bytes");
|
||||
return $total;
|
||||
}
|
4
W/learn/mi2
Executable file
4
W/learn/mi2
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
perl -I../Mail-IMAPClient-2.2.9 "$@"
|
||||
|
4
W/learn/mi3
Executable file
4
W/learn/mi3
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
perl -I../Mail-IMAPClient-3.28/lib "$@"
|
||||
|
133
W/learn/rpm/imapsync.spec
Normal file
133
W/learn/rpm/imapsync.spec
Normal file
|
@ -0,0 +1,133 @@
|
|||
# The source cannot be distributed:
|
||||
%{!?nosrc: %define nosrc 1}
|
||||
# to include the source use:
|
||||
# rpm -bs --define 'nosrc 0'
|
||||
|
||||
%{?!imapsyncver: %define imapsyncver 1.434}
|
||||
|
||||
Summary: Tool to migrate across IMAP servers
|
||||
Name: imapsync
|
||||
Version: %{imapsyncver}
|
||||
Release: 1%{?dist}
|
||||
License: WTFPL
|
||||
Group: Applications/Internet
|
||||
URL: http://www.linux-france.org/prj/imapsync/
|
||||
|
||||
Source: http://www.linux-france.org/prj/imapsync/dist/imapsync-%{version}.tgz
|
||||
# The source cannot be distributed:
|
||||
%if %{nosrc}
|
||||
NoSource: 0
|
||||
%endif
|
||||
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
|
||||
|
||||
BuildArch: noarch
|
||||
BuildRequires: make
|
||||
BuildRequires: perl(Mail::IMAPClient) >= 3.19
|
||||
BuildRequires: perl(Test::More)
|
||||
Requires: perl(Date::Manip)
|
||||
Requires: perl(Digest::MD5)
|
||||
Requires: perl(IO::Socket::SSL)
|
||||
Requires: perl(Mail::IMAPClient) >= 3.19
|
||||
Requires: perl(Term::ReadKey)
|
||||
Requires: perl(Digest::HMAC_MD5)
|
||||
#Requires: perl(Digest::MD5::M4p)
|
||||
#Requires: perl(Net::SSLeay)
|
||||
|
||||
# http://fedoraproject.org/wiki/Packaging:AutoProvidesAndRequiresFiltering
|
||||
%{?filter_setup:
|
||||
%filter_from_requires /^perl(--prefix2)/d
|
||||
%filter_setup
|
||||
}
|
||||
%{!?filter_setup:
|
||||
# filter_setup undefined
|
||||
%define __perl_requires %{_builddir}/%{buildsubdir}/filter-requires-imapsync.sh
|
||||
}
|
||||
|
||||
%description
|
||||
imapsync is a tool for facilitating incremental recursive IMAP
|
||||
transfers from one mailbox to another. It is useful for mailbox
|
||||
migration, and reduces the amount of data transferred by only copying
|
||||
messages that are not present on both servers. Read, unread, and
|
||||
deleted flags are preserved, and the process can be stopped and
|
||||
resumed. The original messages can optionally be deleted after a
|
||||
successful transfer.
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
%{!?filter_setup:
|
||||
%{__cat} <<'EOF' >filter-requires-imapsync.sh
|
||||
#!/bin/sh
|
||||
/usr/lib/rpm/perl.req $* | sed -e '/perl(--prefix2)/d'
|
||||
EOF
|
||||
%{__chmod} a+x filter-requires-imapsync.sh
|
||||
}
|
||||
|
||||
%build
|
||||
|
||||
%install
|
||||
%{__rm} -rf %{buildroot}
|
||||
%{__make} install DESTDIR="%{buildroot}"
|
||||
|
||||
%files
|
||||
%defattr(-, root, root, 0755)
|
||||
%doc ChangeLog COPYING CREDITS FAQ INSTALL README TODO
|
||||
%doc %{_mandir}/man1/imapsync.1*
|
||||
%{_bindir}/imapsync
|
||||
|
||||
%clean
|
||||
%{__rm} -rf %{buildroot}
|
||||
|
||||
%changelog
|
||||
* Fri Mar 25 2011 Marcin Dulak <Marcin.Dulak@gmail.com> - 1.440-1
|
||||
- Updated to release 1.440.
|
||||
- introduced nosrc variable: source must not be distributed
|
||||
- license is WTFPL: see ChangeLog
|
||||
- use filter-requires-imapsync.sh when filter_setup undefined
|
||||
- removed Authority: dag
|
||||
|
||||
* Tue Sep 07 2010 Dag Wieers <dag@wieers.com> - 1.350-1
|
||||
- Updated to release 1.350.
|
||||
|
||||
* Wed Jan 13 2010 Steve Huff <shuff@vecna.org> - 1.293-1
|
||||
- Updated to version 1.293.
|
||||
|
||||
* Sun Dec 20 2009 Steve Huff <shuff@vecna.org> - 1.286-2
|
||||
- Added missing Perl dependencies (reported by John Thomas).
|
||||
|
||||
* Thu Sep 10 2009 Dag Wieers <dag@wieers.com> - 1.286-1
|
||||
- Updated to release 1.286.
|
||||
|
||||
* Thu Jul 09 2009 Christoph Maser <cmr@financial.com> - 1.285-1
|
||||
- Updated to release 1.285.
|
||||
|
||||
* Mon Jun 30 2008 Dag Wieers <dag@wieers.com> - 1.255-1
|
||||
- Updated to release 1.255.
|
||||
|
||||
* Fri May 09 2008 Dag Wieers <dag@wieers.com> - 1.252-1
|
||||
- Updated to release 1.252.
|
||||
|
||||
* Sun Apr 27 2008 Dag Wieers <dag@wieers.com> - 1.250-1
|
||||
- Updated to release 1.250.
|
||||
|
||||
* Wed Mar 26 2008 Dag Wieers <dag@wieers.com> - 1.249-1
|
||||
- Updated to release 1.249.
|
||||
|
||||
* Mon Feb 11 2008 Dag Wieers <dag@wieers.com> - 1.241-1
|
||||
- Updated to release 1.241.
|
||||
|
||||
* Thu Nov 22 2007 Dag Wieers <dag@wieers.com> - 1.233-1
|
||||
- Updated to release 1.233.
|
||||
|
||||
* Thu Sep 13 2007 Dag Wieers <dag@wieers.com> - 1.223-1
|
||||
- Updated to release 1.223.
|
||||
|
||||
* Thu Aug 16 2007 Fabian Arrotin <fabian.arrotin@arrfab.net> - 1.219-1
|
||||
- Update to 1.219.
|
||||
- Cosmetic changes for Requires: specific to RHEL/CentOS.
|
||||
|
||||
* Mon Mar 19 2007 Neil Brown <neilb@inf.ed.ac.uk>
|
||||
- Packaged up source tarball into the RPM. Had to add a fix
|
||||
to stop the perl_requires script wrongly matching on "use --prefix"
|
||||
in the docs as a genuine perl "use module;"
|
27
W/learn/separator
Executable file
27
W/learn/separator
Executable file
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
my $f_sep = $ARGV[0] || "/";
|
||||
my $t_sep = $ARGV[1] || ".";
|
||||
my $o_sep = "\000";
|
||||
|
||||
foreach my $f_fold ("testsub/testsub3", "testsub.testsub3", "a.b/c.d/e" ) {
|
||||
my $t_fold;
|
||||
print "From Folder [$f_fold]\n";
|
||||
$t_fold = $f_fold;
|
||||
my $t_fold2 = $t_fold3 = $f_fold;
|
||||
|
||||
$t_fold =~ s¤\Q$f_sep¤$t_sep¤g;
|
||||
$t_fold2 =~ s¤\Q$t_sep¤$f_sep¤g;
|
||||
$t_fold3 =~ s¤\Q$t_sep¤$o_sep¤g;
|
||||
$t_fold4 = $t_fold3;
|
||||
$t_fold4 =~ s¤\Q$f_sep¤$t_sep¤g;
|
||||
$t_fold5 = $t_fold4;
|
||||
$t_fold5 =~ s¤\Q$o_sep¤$f_sep¤g;
|
||||
|
||||
#$t_fold =~ s¤/¤.¤g;
|
||||
print "To $f_sep$t_sep /. Folder [$t_fold]\n";
|
||||
print "To $t_sep$f_sep ./ Folder2[$t_fold2]\n";
|
||||
print "To $t_sep"."0 .0 Folder3[$t_fold3]\n";
|
||||
print "To $f_sep$t_sep of .0 Folder4[$t_fold4]\n";
|
||||
print "To 0$f_sep 0/ Folder5[$t_fold5]\n\n";
|
||||
}
|
12
W/learn/splice_fetch
Normal file
12
W/learn/splice_fetch
Normal file
|
@ -0,0 +1,12 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
|
||||
|
||||
$rt_big = [1..1000];
|
||||
|
||||
|
||||
while (@t_small = splice(@$rt_big, 0, 33)) {
|
||||
$rt_small = \@t_small;
|
||||
print "@{$rt_small}", "\n";
|
||||
|
||||
}
|
24
W/learn/subscribe
Executable file
24
W/learn/subscribe
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
use Mail::IMAPClient;
|
||||
|
||||
$ARGV[1] or die "usage: $0 user password\n";
|
||||
|
||||
$host = "localhost";
|
||||
$user = $ARGV[0];
|
||||
$password = $ARGV[1];
|
||||
|
||||
my $imap = Mail::IMAPClient->new();
|
||||
#$imap->Debug(1);
|
||||
$imap->Server($host);
|
||||
$imap->connect() or die;
|
||||
$imap->User($user);
|
||||
$imap->Password($password);
|
||||
$imap->login() or die;
|
||||
$imap->subscribe("shared.Spam") or die;
|
||||
print "$user subscribed to\n",
|
||||
join("\n", $imap->subscribed()),
|
||||
"\n";
|
||||
$imap->close();
|
||||
|
||||
|
19
W/learn/uppercase_header
Executable file
19
W/learn/uppercase_header
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
|
||||
@val = (
|
||||
"aBaBaBBaa: aBaBaB: aBaBaB",
|
||||
" message-ad : ",
|
||||
"Message-Id blabla",
|
||||
" aaaa : aaaaa BBBB",
|
||||
" aaaa : aaa:aa BBBB",
|
||||
"",
|
||||
);
|
||||
|
||||
|
||||
foreach $val (@val) {
|
||||
$val = $val;
|
||||
print "[$val]", "\n";
|
||||
$val =~ s/^\s*(.+?):(.+)$/\U$1\E:$2/;
|
||||
print "[$val]", "\n\n";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue