Re: command line deletion of files

2016-09-29 Thread Bron Gondwana via Info-cyrus
Ahh, and reading on I see that this exists already :)

On Fri, 30 Sep 2016, at 08:02, Bron Gondwana wrote:
> You're the reason we can't have nice things :( rm + reconstruct will bite you 
> one upgrade for sure.
> 
> A dry run option to ipurge sounds like a great idea. We just always use IMAP 
> to do admin on Cyrus, but I can see a case for improving ipurge.
> 
> On Fri, 30 Sep 2016, at 01:04, Vladislav Kurz via Info-cyrus wrote:
> > On 09/29/16 16:32, Patrick Boutilier via Info-cyrus wrote:
> > > On 09/29/2016 11:27 AM, Shawn Bakhtiar via Info-cyrus wrote:
> > >> Good morning,
> > >>
> > >> trying to get rid of some emails that have large attachments (i.e.
> > >> videos sent over email, or cd images, etc...)
> > >>
> > >> Would it be proper to
> > >>
> > >> rm -rf /var/spool/imap/u/username/mailbox/4321.
> > >>
> > >> then
> > >>
> > >> reconstruct -rf user.username
> > >>
> > >> Or is there a more "proper" way using cyrus?
> > > 
> > > Not sure about deleting a single message but you can use ipurge to
> > > delete messages based on size. Good to use in a script to parses the
> > > mail spool.
> > > 
> > 
> > rm + reconstruct is IMHO ok, we use that for trash/spam cleanup,
> > antivirus checks, and similar things.
> > 
> > ipurge is nice but I would really appreciate if it had a --dry-run
> > option. I'm never sure what it will really delete.
> > 
> > 
> > -- 
> > Best Regards
> > Vladislav Kurz
> > 
> > 
> > Cyrus Home Page: http://www.cyrusimap.org/
> > List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
> > To Unsubscribe:
> > https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus
> 
> 
> -- 
>   Bron Gondwana
>   br...@fastmail.fm


-- 
  Bron Gondwana
  br...@fastmail.fm

Cyrus Home Page: http://www.cyrusimap.org/
List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
To Unsubscribe:
https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus


Re: command line deletion of files

2016-09-29 Thread Bron Gondwana via Info-cyrus
You're the reason we can't have nice things :( rm + reconstruct will bite you 
one upgrade for sure.

A dry run option to ipurge sounds like a great idea. We just always use IMAP to 
do admin on Cyrus, but I can see a case for improving ipurge.

On Fri, 30 Sep 2016, at 01:04, Vladislav Kurz via Info-cyrus wrote:
> On 09/29/16 16:32, Patrick Boutilier via Info-cyrus wrote:
> > On 09/29/2016 11:27 AM, Shawn Bakhtiar via Info-cyrus wrote:
> >> Good morning,
> >>
> >> trying to get rid of some emails that have large attachments (i.e.
> >> videos sent over email, or cd images, etc...)
> >>
> >> Would it be proper to
> >>
> >> rm -rf /var/spool/imap/u/username/mailbox/4321.
> >>
> >> then
> >>
> >> reconstruct -rf user.username
> >>
> >> Or is there a more "proper" way using cyrus?
> > 
> > Not sure about deleting a single message but you can use ipurge to
> > delete messages based on size. Good to use in a script to parses the
> > mail spool.
> > 
> 
> rm + reconstruct is IMHO ok, we use that for trash/spam cleanup,
> antivirus checks, and similar things.
> 
> ipurge is nice but I would really appreciate if it had a --dry-run
> option. I'm never sure what it will really delete.
> 
> 
> -- 
> Best Regards
> Vladislav Kurz
> 
> 
> Cyrus Home Page: http://www.cyrusimap.org/
> List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
> To Unsubscribe:
> https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus


-- 
  Bron Gondwana
  br...@fastmail.fm

Cyrus Home Page: http://www.cyrusimap.org/
List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
To Unsubscribe:
https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus


Re: command line deletion of files

2016-09-29 Thread John Wade via Info-cyrus
We use a perl scrip that does similar process to delete mass phishing or 
malware email messages from the mail spool. The script locates the 
sequence number for the message based on the message ID/filename, and 
then issues the IMAP delete and expunge commands.


Relevant section of code below  (This is called from a subroutine that 
uses File::Find to locate the files in the file system, but it could be 
called with a simple list of files.) Advantage over ipurge is that this 
is not based on date or size but a specific set of files.


Enjoy,
John

use Net::IMAP::Simple;
use Cyrus::IMAP::Admin;

sub imapdeletemessage {
( my $path ) = @_;
## Extract out foldername and filename (UID) from path
$path =~ /\/var\/spool\/imap\/\d\/(.*)\/(\d+.)/;
my $foldername = $1;
my $messageuid = $2;
return "Error: Unable to identify folder or message for $path" if ( 
! defined($foldername) || ! defined ($messageuid) );

$foldername =~ s/\//\./g;
$messageuid =~ s/\.$//g;
## Give ourselves permissions
if ( my $err = &setimapacl($foldername, 'rte')) {
   return "$err";
}

# Create the IMAP object
my $imap = Net::IMAP::Simple->new('localhost') ||
   die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n";

# Log on
if(!$imap->login($CYRUSADMIN,$CYRUSADMINPW)){
print STDERR "Login failed: " . $imap->errstr . "\n";
exit(64);
}

## Select folder and get number of messages
my $nm = $imap->select($foldername);
if ( $imap->waserr || ! defined($nm)  ) {
   &setimapacl($foldername, 'none');
   return "ERROR: unable to select $foldername: " . $imap->errstr;
}

### Now get Sequence Number for Message ID
my @seq = $imap->seq($messageuid);
if ( ! defined($seq[0])) {
   &setimapacl($foldername, 'none');
   return "ERROR: No sequence number for UID $messageuid 
$foldername, probably deleted\n";

}
# print "seq for uid $messageuid is $seq[0]\n";

## Delete the message
if ( ! $imap->delete( $seq[0] )) {
   &setimapacl($foldername, 'none');
   return "ERROR: Unable to delete $messageuid from $foldername: " 
. $imap->errstr;

}

## Expunge the mailbox to be safe
my $expunged = $imap->expunge_mailbox( $foldername );
if  ( $imap->waserr ) {
&setimapacl($foldername, 'none');
return "ERROR: unabled to expunge $foldername: " . $imap->errstr;
}
$imap->quit;
print "IMAP Deleted: UID:$messageuid from folder:$foldername\n";
print LOG "IMAP Deleted: UID:$messageuid from folder:$foldername\n" 
if ( $logfile);


## Take away our permissions
if ( my $err = &setimapacl($foldername, 'none')) {
   return "$err";
}
return 0;
};


On 09/29/2016 11:27 AM, Shawn Bakhtiar via Info-cyrus wrote:

Good morning,

trying to get rid of some emails that have large attachments (i.e. 
videos sent over email, or cd images, etc...)


Would it be proper to

rm -rf /var/spool/imap/u/username/mailbox/4321.

then

reconstruct -rf user.username

Or is there a more "proper" way using cyrus?





Cyrus Home Page: http://www.cyrusimap.org/
List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
To Unsubscribe:
https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus


Re: command line deletion of files

2016-09-29 Thread Vladislav Kurz via Info-cyrus
On 09/29/16 17:14, Wolfgang Breyha via Info-cyrus wrote:
> Vladislav Kurz via Info-cyrus wrote on 29/09/16 17:04:
>> ipurge is nice but I would really appreciate if it had a --dry-run
>> option. I'm never sure what it will really delete.
> 
> It got one in 2.5.9.
> 
> Greetings, Wolfgang
> 
Ah, thank you very much. +1 (like, thumbsup, etc ;)

-- 
Best regards
Vladislav Kurz


Cyrus Home Page: http://www.cyrusimap.org/
List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
To Unsubscribe:
https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus


Re: command line deletion of files

2016-09-29 Thread Wolfgang Breyha via Info-cyrus
Vladislav Kurz via Info-cyrus wrote on 29/09/16 17:04:
> ipurge is nice but I would really appreciate if it had a --dry-run
> option. I'm never sure what it will really delete.

It got one in 2.5.9.

Greetings, Wolfgang
-- 
Wolfgang Breyha  | http://www.blafasel.at/
Vienna University Computer Center | Austria


Cyrus Home Page: http://www.cyrusimap.org/
List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
To Unsubscribe:
https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus


Re: command line deletion of files

2016-09-29 Thread Vladislav Kurz via Info-cyrus
On 09/29/16 16:32, Patrick Boutilier via Info-cyrus wrote:
> On 09/29/2016 11:27 AM, Shawn Bakhtiar via Info-cyrus wrote:
>> Good morning,
>>
>> trying to get rid of some emails that have large attachments (i.e.
>> videos sent over email, or cd images, etc...)
>>
>> Would it be proper to
>>
>> rm -rf /var/spool/imap/u/username/mailbox/4321.
>>
>> then
>>
>> reconstruct -rf user.username
>>
>> Or is there a more "proper" way using cyrus?
> 
> Not sure about deleting a single message but you can use ipurge to
> delete messages based on size. Good to use in a script to parses the
> mail spool.
> 

rm + reconstruct is IMHO ok, we use that for trash/spam cleanup,
antivirus checks, and similar things.

ipurge is nice but I would really appreciate if it had a --dry-run
option. I'm never sure what it will really delete.


-- 
Best Regards
Vladislav Kurz


Cyrus Home Page: http://www.cyrusimap.org/
List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
To Unsubscribe:
https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus


Re: command line deletion of files

2016-09-29 Thread Dan White via Info-cyrus

On 09/29/16 14:27 +, Shawn Bakhtiar via Info-cyrus wrote:

trying to get rid of some emails that have large attachments (i.e. videos sent 
over email, or cd images, etc...)

Would it be proper to

rm -rf /var/spool/imap/u/username/mailbox/4321.

then

reconstruct -rf user.username

Or is there a more "proper" way using cyrus?


I've found mutt to be useful for this type of maintenance, which can sort
messages by size, and can delete ranges. If you don't have access to user
passwords, set up a 'proxyservers' authz identity to access their
mailboxes.

--
Dan White

Cyrus Home Page: http://www.cyrusimap.org/
List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
To Unsubscribe:
https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus


Re: command line deletion of files

2016-09-29 Thread Patrick Boutilier via Info-cyrus

On 09/29/2016 11:27 AM, Shawn Bakhtiar via Info-cyrus wrote:

Good morning,

trying to get rid of some emails that have large attachments (i.e. videos sent 
over email, or cd images, etc...)

Would it be proper to

rm -rf /var/spool/imap/u/username/mailbox/4321.

then

reconstruct -rf user.username

Or is there a more "proper" way using cyrus?


Not sure about deleting a single message but you can use ipurge to 
delete messages based on size. Good to use in a script to parses the 
mail spool.






IPURGE(8) 
IPURGE(8)


 *

NAME
   ipurge - delete mail from IMAP mailbox or partition based on age 
or size


SYNOPSIS
   ipurge [ -f ] [ -C config-file ] [ -x ] [ -X ] [ -i ] [ -s ] [ -o ]
  [ -d days | -b bytes | -k Kbytes | -m Mbytes ]
  [ mailbox-pattern...  ]

DESCRIPTION
   Ipurge  deletes messages from the mailbox(es) specified by 
mailbox-pattern that are older or larger than specified by the -d, -b, 
-k or -m options.  If no mailbox-pattern
   is given, ipurge works on all mailboxes.  If the -x option is 
given, the message age and size MUST match exactly those specified by 
-d, -b, -k or -m.  The are no  default

   values, and at least one of -d, -b, -k or -m MUST be specified.

   Ipurge  by default only deletes mail below shared folders, which 
means that mails in mailbox(es) below INBOX.* and user.* stay untouched. 
Use the option -f to also delete

   mail in mailbox(es) below these folders.

   Ipurge reads its configuration options out of the imapd.conf(5) 
file unless specified otherwise by -C.


OPTIONS
   -f Force deletion of mail in all mailboxes.

   -C config-file
  Read configuration options from config-file.

   -d days
  Age of message in days.

   -b bytes
  Size of message in bytes.

   -k Kbytes
  Size of message in Kbytes (2^10 bytes).

   -m Mbytes
  Size of message in Mbytes (2^20 bytes).

   -x Perform an exact match on age or size (instead of older 
or larger).


   -X Use delivery time instead of Date: header for date matches

   -i Invert match logic: -x means not equal, date is for 
newer, size is for smaller


   -s Skip over messages that have the \Flagged flag set.

   -o Only purge messages that have the \Deleted flag set.








Thanks,
Shawn


Cyrus Home Page: http://www.cyrusimap.org/
List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
To Unsubscribe:
https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus



<>
Cyrus Home Page: http://www.cyrusimap.org/
List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
To Unsubscribe:
https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus

command line deletion of files

2016-09-29 Thread Shawn Bakhtiar via Info-cyrus
Good morning,

trying to get rid of some emails that have large attachments (i.e. videos sent 
over email, or cd images, etc...)

Would it be proper to 

rm -rf /var/spool/imap/u/username/mailbox/4321.

then

reconstruct -rf user.username

Or is there a more "proper" way using cyrus?

Thanks,
Shawn


Cyrus Home Page: http://www.cyrusimap.org/
List Archives/Info: http://lists.andrew.cmu.edu/pipermail/info-cyrus/
To Unsubscribe:
https://lists.andrew.cmu.edu/mailman/listinfo/info-cyrus