Skip to content

Commit

Permalink
Item12180: Include S/MIME in autoconfig
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@16266 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
TimotheLitt authored and TimotheLitt committed Dec 24, 2012
1 parent f262f84 commit 5c0c7b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
42 changes: 35 additions & 7 deletions core/lib/Foswiki/Configure/Checkers/EnableEmail.pm
Expand Up @@ -189,7 +189,35 @@ sub autoconfig {
my $this = shift;
my ($options) = @_;

my $e = '';
my $e = '';
my $sm = '';

if ( $Foswiki::cfg{Email}{EnableSMIME} ) {
my ( $certFile, $keyFile ) = (
$Foswiki::cfg{Email}{SmimeCertificateFile},
$Foswiki::cfg{Email}{SmimeKeyFile},
);
unless ( $certFile && $keyFile ) {
( $certFile, $keyFile ) = (
'$Foswiki::cfg{DataDir}/SmimeCertificate.pem',
'$Foswiki::cfg{DataDir}/SmimePrivateKey.pem',
);
}
Foswiki::Configure::Load::expandValue($certFile);
Foswiki::Configure::Load::expandValue($keyFile);

unless ( $certFile && $keyFile && -r $certFile && -r $keyFile ) {
$e .= $this->ERROR(
"We recommend configuring Foswiki to send S/MIME signed e-mail.<p>
To do this, either Certificate and Key files must be provided, or a self-signed certificate can be generated.<p>
To generate a self-signed certificate or generate a signing request, use the respective WebmasterName action button.<p>
Because no certificate is present, S/MIME his been disabled to allow basic autoconfiguration to continue."
);
$sm .=
$this->FB_VALUE(
$this->setItemValue( 0, '{Email}{EnableSMIME}' ) );
}
}

# Prefer perl or program?

Expand All @@ -202,13 +230,13 @@ sub autoconfig {
}

if ($preferPerl) {
( my $ok, $e ) = $this->autoconfigPerl( $options, 0 );
return $e if ($ok);
return $e . ( $this->autoconfigProgram( $options, -1 ) )[1];
my ( $ok, $ae ) = $this->autoconfigPerl( $options, 0 );
return $e . $ae . $sm if ($ok);
return $e . $ae . ( $this->autoconfigProgram( $options, -1 ) )[1] . $sm;
}
( my $ok, $e ) = $this->autoconfigProgram( $options, 1 );
return $e if ($ok);
return $e . ( $this->autoconfigPerl( $options, -1 ) )[1];
my ( $ok, $ae ) = $this->autoconfigProgram( $options, 1 );
return $e . $ae . $sm if ($ok);
return $e . $ae . ( $this->autoconfigPerl( $options, -1 ) )[1] . $sm;
}

sub autoconfigProgram {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/Foswiki/Net.pm
Expand Up @@ -591,7 +591,7 @@ sub _smimeSignMessage {
"$Foswiki::cfg{DataDir}/SmimePrivateKey.pem"
);

unless ( -r $certFile && -r $keyFile ) {
unless ( $certFile && $keyFile && -r $certFile && -r $keyFile ) {
$this->_logMailError( 'die',
"Signed (S/MIME) mail is enabled, but certificate or key is not specified and no self-signed certificate is available."
);
Expand Down

0 comments on commit 5c0c7b5

Please sign in to comment.