User Tools

Site Tools


software:dovecot:archiveserver

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
software:dovecot:archiveserver [2023/07/28 17:35] rodolicosoftware:dovecot:archiveserver [2023/09/25 15:19] (current) rodolico
Line 25: Line 25:
 ===== Create a user and store for the e-mail ===== ===== Create a user and store for the e-mail =====
  
-We should use a different user/group for this and all mail will be owned by that user/group. Additionally, we don't want a login, so we'll set the shell to /dev/false. We'll also tell the adduser script to not create the home directory (we'll create it ourselves),+We should use a different user/group for this and all mail will be owned by that user/group. Additionally, we don't want a login, so we'll set the shell to /bin/false. We'll also tell the adduser script to not create the home directory (we'll create it ourselves),
  
 Message store (ie, home directory) can be anyplace. I'm going to set it up in /srv/vmail. This will be the head of a tree of subdirectories for individual users. Note, I use useradd (vs Debian's adduser) for simplicity. Message store (ie, home directory) can be anyplace. I'm going to set it up in /srv/vmail. This will be the head of a tree of subdirectories for individual users. Note, I use useradd (vs Debian's adduser) for simplicity.
  
 <code bash> <code bash>
-useradd --home-dir /srv/vmail --no-create-home --shell /dev/false --user-group --comment 'Used for vmail only' vmail+useradd --home-dir /srv/vmail --no-create-home --shell /bin/false --user-group --comment 'Used for vmail only' vmail
 mkdir -p /srv/vmail mkdir -p /srv/vmail
 chmod 755 /srv/vmail chmod 755 /srv/vmail
Line 119: Line 119:
  
 which would give us greater security. which would give us greater security.
 +
 +If you want, here is a little utility written in Perl that will do all of it for you. It takes a username and a password, then either updates or adds that information to the password file. It is NOT very friendly, and could use some cleanup, and the username/password are left in your history file, so it is insecure. Call it with <code bash>./updatePasswd username 'password'</code>
 +
 +<code perl updatePasswd>
 +#! /usr/bin/env perl
 +
 +# WARNING: This is insecure as it will leave the users password in the 
 +# bash history file
 +
 +use strict;
 +use warnings;
 +
 +my $pwfile = '/srv/vmail/passwd'; # location of the password file
 +my $user = shift;
 +my $password = shift;
 +
 +die "Usage: $0 username password\n" unless $user && $password;
 +
 +my $found = 0; # determines if user already exists
 +
 +# call doveadm to get the hash
 +my $key = `/usr/bin/doveadm pw -s ssha256 -u '$user' -p '$password'`;
 +
 +# read the password file
 +open PW,"<$pwfile" or die "Could not open the password file: $!\n";
 +my @data = <PW>;
 +close PW;
 +
 +# go through it and see if the user already exists
 +my $newLine = "$user:$key";
 +for ( my $line = 0; $line < @data; $line++ ) {
 +   my ($thisUser,$thisPass) = split( ':', $data[$line] );
 +   if ( $thisUser eq $user ) { # yes, so replace the line and mark found
 +      $data[$line] = $newLine;
 +      $found = 1;
 +      last;
 +   } # if statement
 +} # for loop
 +push @data, $newLine unless $found; # we did not find them, so add
 +chomp @data; # remove all line endings
 +
 +# write the file back out
 +open PW,">$pwfile" or die "Could not write the password file: $!\n";
 +print PW join( "\n", @data ) . "\n";
 +close PW;
 +
 +# tell user what we did
 +print "User $user ";
 +print $found ? "modified\n" : "added\n";
 +
 +1;
 +</code>
 +
 +
  
 ===== Setting up mail client ===== ===== Setting up mail client =====
Line 193: Line 247:
  
 The script could also be set up to remove MIME attachments and store them. A good place to start on that would be in the article [[http://www.perlmonks.org/bare/?node_id=525036]] where they describe how to pull a MIME attachment out and store it as a file. The script could then replace the MIME attachment code in the e-mail with a link to the extracted file. The script could also be set up to remove MIME attachments and store them. A good place to start on that would be in the article [[http://www.perlmonks.org/bare/?node_id=525036]] where they describe how to pull a MIME attachment out and store it as a file. The script could then replace the MIME attachment code in the e-mail with a link to the extracted file.
 +
 +===== Errors =====
 +
 +Some e-mail, especially older ones or spam, have malformed dates, or dates which can not be processed by the Perl libraries. In this case, you may receive an error similar to
 +<code>
 +Use of uninitialized value $t[4] in addition (+) at ./archiveIMAP line 234, <GEN3> line 720660.
 +</code>
 +and the e-mail in question will **not** be processed. If you find lines like this in your logs, or if you see some older e-mail not being moved, you will need to move manually or delete them.
software/dovecot/archiveserver.1690583759.txt.gz · Last modified: 2023/07/28 17:35 by rodolico