diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index 3c1804a326220803c8cea9e4664cd8b26643e53c..3c4306d1eeffe17cb65a2b2207f18be1312d6f11 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -220,9 +220,28 @@ class MailFetcher { return imap_utf7_encode($mailbox); } - //Generic decoder - resulting text is utf8 encoded -> mirrors imap_utf8 + /** + * Mime header value decoder. Usually unicode characters are encoded + * according to RFC-2047. This function will decode RFC-2047 encoded + * header values as well as detect headers which are not encoded. + * + * Caveats: + * If headers contain non-ascii characters the result of this function + * is completely undefined. If osTicket is corrupting your email + * headers, your mail software is not encoding the header text + * correctly. + * + * Returns: + * Header value, transocded to UTF-8 + */ function mime_decode($text, $encoding='utf-8') { + // Handle poorly or completely un-encoded header values ( + if (function_exists('mb_detect_encoding')) + if (($src_enc = mb_detect_encoding($text)) + && (strcasecmp($src_enc, 'ASCII') !== 0)) + return Format::encode($text, $src_enc, $encoding); + // Handle ASCII text and RFC-2047 encoding $str = ''; $parts = imap_mime_header_decode($text); foreach ($parts as $part) @@ -298,7 +317,11 @@ class MailFetcher { $struct=@imap_fetchstructure($this->mbox, $mid); //Match the mime type. - if($struct && !$struct->ifdparameters && strcasecmp($mimeType, $this->getMimeType($struct))==0) { + if($struct + && strcasecmp($mimeType, $this->getMimeType($struct))==0 + && (!$struct->ifdparameters + || !$this->findFilename($struct->dparameters))) { + $partNumber=$partNumber?$partNumber:1; if(($text=imap_fetchbody($this->mbox, $mid, $partNumber))) { if($struct->encoding==3 or $struct->encoding==4) //base64 and qp decode. diff --git a/setup/scripts/api_ticket_create.php b/setup/scripts/api_ticket_create.php new file mode 100755 index 0000000000000000000000000000000000000000..ae968019443772b9b01afa7a891f6cb725a2f09c --- /dev/null +++ b/setup/scripts/api_ticket_create.php @@ -0,0 +1,63 @@ +#!/usr/bin/php -q +<?php +# +# Configuration: Enter the url and key. That is it. +# url => URL to api/task/cron e.g # http://yourdomain.com/support/api/tickets.json +# key => API's Key (see admin panel on how to generate a key) +# + +$config = array( + 'url'=>'http://domain.com/api/tickets.json', + 'key'=>'<api key>' + ); + +# Fill in the data for the new ticket, this will likely come from $_POST. + +$data = array( + 'name' => 'John Doe', + 'email' => 'mailbox@host.com', + 'subject' => 'Test API message', + 'message' => 'This is a test of the osTicket API', + 'ip' => $_SERVER['REMOTE_ADDR'], + 'attachments' => array(), +); + +/* + * Add in attachments here if necessary + +$data['attachments'][] = +array('filename.pdf' => + 'data:image/png;base64,' . + base64_encode(file_get_contents('/path/to/filename.pdf'))); + */ + +#pre-checks +function_exists('curl_version') or die('CURL support required'); +function_exists('json_encode') or die('JSON support required'); + +#set timeout +set_time_limit(30); + +#curl post +$ch = curl_init(); +curl_setopt($ch, CURLOPT_URL, $config['url']); +curl_setopt($ch, CURLOPT_POST, 1); +curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); +curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7'); +curl_setopt($ch, CURLOPT_HEADER, FALSE); +curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key'])); +curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); +$result=curl_exec($ch); +$code = curl_getinfo($ch, CURLINFO_HTTP_CODE); +curl_close($ch); + +if ($code != 201) + die('Unable to create ticket: '.$result); + +$ticket_id = (int) $result; + +# Continue onward here if necessary. $ticket_id has the ID number of the +# newly-created ticket + +?>