| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * SquirrelMail NewMail plugin |
| 5 | * |
| 6 | * Script loads user's media file. |
| 7 | * |
| 8 | * @copyright © 2001-2007 The SquirrelMail Project Team |
| 9 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 10 | * @version $Id$ |
| 11 | * @package plugins |
| 12 | * @subpackage newmail |
| 13 | */ |
| 14 | |
| 15 | /** |
| 16 | * Path for SquirrelMail required files. |
| 17 | * @ignore |
| 18 | */ |
| 19 | require('../../include/init.php'); |
| 20 | /** Load plugin functions */ |
| 21 | include_once(SM_PATH . 'plugins/newmail/functions.php'); |
| 22 | |
| 23 | sqgetGlobalVar('username',$username,SQ_SESSION); |
| 24 | global $data_dir; |
| 25 | |
| 26 | $media = getPref($data_dir,$username,'newmail_media', '(none)'); |
| 27 | // get other prefs |
| 28 | $newmail_userfile_type=getPref($data_dir,$username,'newmail_userfile_type',false); |
| 29 | |
| 30 | $newmail_userfile_location=getHashedFile($username, $data_dir, $username . '.sound'); |
| 31 | |
| 32 | if ($newmail_uploadsounds && $newmail_userfile_type!=false && file_exists($newmail_userfile_location)) { |
| 33 | // open media file |
| 34 | $newmail_userfile_handle = fopen($newmail_userfile_location,'rb'); |
| 35 | if ($newmail_userfile_handle) { |
| 36 | $newmail_userfile_filesize = filesize($newmail_userfile_location); |
| 37 | $newmail_userfile_contents = fread($newmail_userfile_handle,$newmail_userfile_filesize); |
| 38 | fclose ($newmail_userfile_handle); |
| 39 | |
| 40 | // user prefs use only integer values to store file type |
| 41 | switch($newmail_userfile_type) { |
| 42 | case SM_NEWMAIL_FILETYPE_WAV: |
| 43 | // wav file |
| 44 | $newmail_userfile_contenttype='audio/x-wav'; |
| 45 | break; |
| 46 | case SM_NEWMAIL_FILETYPE_MP3: |
| 47 | // mp3 file |
| 48 | $newmail_userfile_contenttype='audio/mpeg'; |
| 49 | break; |
| 50 | case SM_NEWMAIL_FILETYPE_OGG: |
| 51 | // ogg file |
| 52 | $newmail_userfile_contenttype='application/ogg'; |
| 53 | break; |
| 54 | case SM_NEWMAIL_FILETYPE_SWF: |
| 55 | // flash file |
| 56 | $newmail_userfile_contenttype='application/x-shockwave-flash'; |
| 57 | break; |
| 58 | case SM_NEWMAIL_FILETYPE_SVG: |
| 59 | // svg file |
| 60 | $newmail_userfile_contenttype='image/svg+xml'; |
| 61 | break; |
| 62 | default: |
| 63 | // none of above |
| 64 | $newmail_userfile_contenttype='unknown'; |
| 65 | } |
| 66 | |
| 67 | // make sure that media file is in correct format |
| 68 | $newmail_userfile_extension=newmail_detect_filetype($newmail_userfile_contents,$newmail_userfile_contenttype); |
| 69 | |
| 70 | // last check before sending file contents to browser. |
| 71 | if ($newmail_userfile_extension!=false) { |
| 72 | $newmail_send_filename='mediafile.' . $newmail_userfile_extension; |
| 73 | header ('Content-Disposition: inline; filename="' . $newmail_send_filename . '"'); |
| 74 | header('Content-Type: "' . $newmail_userfile_contenttype .'"; ' . |
| 75 | 'name="' . $newmail_send_filename . '"'); |
| 76 | header('Content-Length: ' . $newmail_userfile_filesize ); |
| 77 | echo $newmail_userfile_contents; |
| 78 | exit; |
| 79 | } // file type detection failed |
| 80 | } // failed to open userfile |
| 81 | } // userfile is missing or preferences don't store file type. |
| 82 | // maybe we should send some error code |