$mimetype = $type[(int) $info->parts[$counter]->type] . '/' . $info->parts[$counter]->subtype; $mimetype = strtolower($mimetype); echo " - File: {$filename} ({$mimetype})... "; $fullfilename = 'tmp/attachments/' . $uid . '/' . $filename; $file = 'tmp/attachments/' . $uid . '/mail.txt'; imap_savebody($inbox, $file, $message->msgno); $parser = new MimeMailParser(); $parser->setPath($file); $attachments = $parser->getAttachmentsAsStreams(); file_put_contents($fullfilename, $attachments[$counter - 1]); echo "done\n"; $package->addFile($filename, $mimetype); $counter++; } // Deposit the package $package->create(); $client = new SWORDAPPClient(); $response = $client->deposit($swordurl, $sworduser, $swordpassword, '', 'tmp/' . $packagefilename, 'http://purl.org/net/sword-types/METSDSpaceSIP', 'application/zip', false, true); // print_r($response); $id = $response->sac_id; $id = str_replace("http://hdl.handle.net/", "http://dspace.swordapp.org/jspui/handle/", $id); echo "Deposited at " . $id . "\n\n"; $to = $message->from; $from = "From: " . $mailuser; $subject = "Deposit successful: " . $id; $contents = "Thanks you for your deposit. It can be viewed at " . $id; mail($to, $subject, $contents, $from); // Mark the message as read imap_setflag_full($inbox, $message->msgno, "\\Seen"); } }
$test_citation = 'Allinson, J., Francois, S., Lewis, S. SWORD: Simple Web-service Offering Repository Deposit, Ariadne, Issue 54, January 2008. Online at http://www.ariadne.ac.uk/issue54/'; // Identifier $test_identifier = 'http://www.ariadne.ac.uk/issue54/allinson-et-al/'; // Date made available $test_dateavailable = '2008-01'; // Copyright holder $test_copyrightholder = 'Julie Allinson, Sebastien Francois, Stuart Lewis'; // Custodian $test_custodian = 'Julie Allinson, Sebastien Francois, Stuart Lewis'; // Status statement $test_statusstatement = 'http://purl.org/eprint/status/PeerReviewed'; // File name $test_file = 'SWORD Ariadne Jan 2008.pdf'; // MIME type of file $test_mimetype = 'application/pdf'; $test_packager = new PackagerMetsSwap($test_rootin, $test_dirin, $test_rootout, $test_fileout); $test_packager->setCustodian($test_custodian); $test_packager->setType($test_type); $test_packager->setTitle($test_title); $test_packager->setAbstract($test_abstract); foreach ($test_creators as $test_creator) { $test_packager->addCreator($test_creator); } $test_packager->setIdentifier($test_identifier); $test_packager->setDateAvailable($test_dateavailable); $test_packager->setStatusStatement($test_statusstatement); $test_packager->setCopyrightHolder($test_copyrightholder); $test_packager->setCitation($test_citation); $test_packager->addFile($test_file, $test_mimetype); $test_packager->create();