mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
parent
6df7b76c8a
commit
51fedab4fc
3 changed files with 34 additions and 9 deletions
|
|
@ -14,14 +14,36 @@ trait Pgp
|
|||
return null;
|
||||
}
|
||||
|
||||
$home = ($_SERVER['HOME'] ?: \exec('echo ~')) . '/.gnupg/';
|
||||
if ($oAccount instanceof \RainLoop\Model\AdditionalAccount) {
|
||||
$home .= \sha1($oAccount->ParentEmail());
|
||||
} else {
|
||||
$home .= \sha1($oAccount->Email());
|
||||
$homedir = \dirname($this->StorageProvider()->GenerateFilePath(
|
||||
$oAccount,
|
||||
\RainLoop\Providers\Storage\Enumerations\StorageType::PGP
|
||||
)) . '/.gnupg';
|
||||
|
||||
/**
|
||||
* Workaround error: socket name for '/very/long/path/to/.gnupg/S.gpg-agent.extra' is too long
|
||||
* BSD 4.4 max length = 104
|
||||
*/
|
||||
if (80 < \strlen($homedir)) {
|
||||
// First try a symbolic link
|
||||
$link = \sys_get_temp_dir() . '/snappymail';
|
||||
if (\is_dir($link) || \mkdir($link, 0700, true)) {
|
||||
$link = $tmpdir . '/' . \md5($homedir);
|
||||
if (\is_link($homedir) || \symlink($homedir, $link)) {
|
||||
$homedir = $link;
|
||||
}
|
||||
}
|
||||
// Else try ~/.gnupg/ + hash(email address)
|
||||
if (80 < \strlen($homedir)) {
|
||||
$homedir = ($_SERVER['HOME'] ?: \exec('echo ~')) . '/.gnupg/';
|
||||
if ($oAccount instanceof \RainLoop\Model\AdditionalAccount) {
|
||||
$homedir .= \sha1($oAccount->ParentEmail());
|
||||
} else {
|
||||
$homedir .= \sha1($oAccount->Email());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return \SnappyMail\PGP\GnuPG::getInstance($home);
|
||||
return \SnappyMail\PGP\GnuPG::getInstance($homedir);
|
||||
}
|
||||
|
||||
public function DoGnupgGetKeys() : array
|
||||
|
|
|
|||
|
|
@ -14,13 +14,15 @@ class GnuPG
|
|||
public static function isSupported() : bool
|
||||
{
|
||||
return \class_exists('gnupg')
|
||||
|| \stream_resolve_include_path('Crypt/GPG.php');
|
||||
|| \stream_resolve_include_path('Crypt/GPG.php')
|
||||
|| \SnappyMail\PGP\GPG::isSupported();
|
||||
}
|
||||
|
||||
public static function getInstance(string $homedir) : ?self
|
||||
{
|
||||
$homedir = \rtrim($homedir, '/\\');
|
||||
if (107 <= \strlen($homedir . '/S.gpg-agent.extra')) {
|
||||
// BSD 4.4 max length
|
||||
if (104 <= \strlen($homedir . '/S.gpg-agent.extra')) {
|
||||
throw new \Exception('socket name for S.gpg-agent.extra is too long');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,8 @@ class GPG
|
|||
function __construct(string $homedir)
|
||||
{
|
||||
$homedir = \rtrim($homedir, '/\\');
|
||||
if (107 <= \strlen($homedir . '/S.gpg-agent.extra')) {
|
||||
// BSD 4.4 max length
|
||||
if (104 <= \strlen($homedir . '/S.gpg-agent.extra')) {
|
||||
throw new \Exception("socket name for '{$homedir}/S.gpg-agent.extra' is too long");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue