function syncExistingAttachments() { $matches = array(); if (!preg_match_all('/"cid:([\\w.-]{32})"/', $this->getBody(), $matches)) { return; } // Purge current attachments $this->attachments->deleteInlines(); foreach ($matches[1] as $hash) { if ($file = AttachmentFile::getIdByHash($hash)) { $this->attachments->upload($file, true); } } }
function lookup($id) { $id = is_numeric($id) ? $id : AttachmentFile::getIdByHash($id); return $id && ($file = new AttachmentFile($id)) && $file->getId() == $id ? $file : null; }