+ protected function &getSignedPart()
+ {
+ if ($this->isType('multipart', 'signed')) {
+ foreach ($this->multipart as &$part) {
+ if ($part->content_type != $this->signature['protocole']) {
+ return $part;
+ }
+ }
+ }
+ return $this;
+ }
+
+ private function checkPGPSignature($signature, $message = null)
+ {
+ $signname = tempnam(Banana::$spool_root, 'banana_pgp_');
+ file_put_contents($signname. '.asc', $signature);
+ $gpg_check = array();
+ if (!is_null($message)) {
+ file_put_contents($signname, str_replace(array("\r\n", "\n"), array("\n", "\r\n"), $message));
+ exec('LC_ALL="en_US" gpg --verify ' . $signname . '.asc ' . $signname . ' 2>&1', $gpg_check, $result);
+ unlink($signname);
+ } else {
+ exec('LC_ALL="en_US" gpg --verify ' . $signname . '.asc 2&>1', $gpg_check, $result);
+ }
+ unlink("$signname.asc");
+ if (preg_match('/Signature made (.+) using (.+) key ID (.+)/', array_shift($gpg_check), $matches)) {
+ $this->signature['date'] = strtotime($matches[1]);
+ $this->signature['key'] = array('format' => $matches[2],
+ 'id' => $matches[3]);
+ } else {
+ return false;
+ }
+ $signature = array_shift($gpg_check);
+ if (preg_match('/Good signature from "(.+)"/', $signature, $matches)) {
+ $this->signature['verify'] = true;
+ $this->signature['identity'] = array($matches[1]);
+ } elseif (preg_match('/BAD signature from "(.+)"/', $signature, $matches)) {
+ $this->signature['verify'] = false;
+ $this->signature['identity'] = array($matches[1]);
+ } else {
+ return false;
+ }
+ foreach ($gpg_check as $aka) {
+ if (preg_match('/aka "(.+)"/', $aka, $matches)) {
+ $this->signature['identity'][] = $matches[1];
+ }
+ }
+ return true;
+ }
+
+ public function getSignature()