3 * SquirrelMail NewMail plugin
5 * Script loads user's media file.
15 define('SM_PATH','../../');
17 /** Load squirrelmail functions */
18 include_once(SM_PATH
. 'include/validate.php');
19 /** Load plugin functions */
20 include_once(SM_PATH
. 'plugins/newmail/functions.php');
22 sqgetGlobalVar('username',$username,SQ_SESSION
);
25 $media = getPref($data_dir,$username,'newmail_media', '(none)');
27 $newmail_userfile_type=getPref($data_dir,$username,'newmail_userfile_type',false);
29 $newmail_userfile_location=getHashedFile($username, $data_dir, $username . '.sound');
31 if ($newmail_userfile_type!=false && file_exists($newmail_userfile_location)) {
33 $newmail_userfile_handle = fopen($newmail_userfile_location,'rb');
34 if ($newmail_userfile_handle) {
35 $newmail_userfile_filesize = filesize($newmail_userfile_location);
36 $newmail_userfile_contents = fread($newmail_userfile_handle,$newmail_userfile_filesize);
37 fclose ($newmail_userfile_handle);
39 // user prefs use only integer values to store file type
40 switch($newmail_userfile_type) {
41 case SM_NEWMAIL_FILETYPE_WAV
:
43 $newmail_userfile_contenttype='audio/x-wav';
45 case SM_NEWMAIL_FILETYPE_MP3
:
47 $newmail_userfile_contenttype='audio/mpeg';
49 case SM_NEWMAIL_FILETYPE_OGG
:
51 $newmail_userfile_contenttype='application/ogg';
53 case SM_NEWMAIL_FILETYPE_SWF
:
55 $newmail_userfile_contenttype='application/x-shockwave-flash';
57 case SM_NEWMAIL_FILETYPE_SVG
:
59 $newmail_userfile_contenttype='image/svg+xml';
63 $newmail_userfile_contenttype='unknown';
66 // make sure that media file is in correct format
67 $newmail_userfile_extension=newmail_detect_filetype($newmail_userfile_contents,$newmail_userfile_contenttype);
69 // last check before sending file contents to browser.
70 if ($newmail_userfile_extension!=false) {
71 $newmail_send_filename='mediafile.' . $newmail_userfile_extension;
72 header ('Content-Disposition: inline; filename="' . $newmail_send_filename . '"');
73 header('Content-Type: "' . $newmail_userfile_contenttype .'"; ' .
74 'name="' . $newmail_send_filename . '"');
75 header('Content-Length: ' . $newmail_userfile_filesize );
76 echo $newmail_userfile_contents;
78 } // file type detection failed
79 } // failed to open userfile
80 } // userfile is missing or preferences don't store file type.
81 // maybe we should send some error code