B
bb-mitch

  • May 17, 2010
  • Joined Mar 5, 2010
  • 0 best answers
  • Could be generated by whatever makes the email...

    You likely have to have the proper file name for the web server to serve the right content type... two options, one is to associate the extension with the proper mime type, the other would be to detect the file name and rename it. Hard for me to guess when I can't see the message. You can probably run the pipe.php from a command shell to debug it - that would allow you to echo some debug information - or you could use the error_log function to throw it to a tmp file...

    Something like:

    error_log(print_r($someobject,TRUE)."\n",3,'/tmp/yourlog.txt');

    Should help you understand what you are getting... the output will tell you more about the structure of the variable you dump to the log while the program runs.

  • You might try making it simpler

    +//THIS PATCH ADDS THE ABILITY TO SAVE EMBEDDED IMAGES IN AN HTML EMAIL FROM OUTLOOK 2007

    +//This just looks for ANY IMAGE

    + } elseif (!strcasecmp($part->ctype_primary,'image')) {

    + //$filename=$part->ctype_parameters;

    + //Assign a name?

    + $filename='NoName';

    + if($filename && $cfg->canUploadFileType($filename)) {

    + $ticket->saveAttachment($filename,$part->body,$msgid,'M');

    + }

    You might need to tweak this. You might want to add some filter - on file size for example. Otherwise you will end up with what I did... every little signature icon being attached as an image. This is not tested.

    Cheers.

  • I've been looking at the code in pipe.php:

    //Strip quoted reply...TODO: figure out how mail clients do it without special tag..

    if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()) && strpos($var,$tag))

    list($message)=split($tag,$var);

    The way the code was written, it only operates on replies - not NEW messages. I have an issue with people submitting tickets and forgetting to delete their bulky signatures / disclaimers / etc.

    My problem is (WAS) twofold.

    1) I want to prevent the signatures.

    2) I want to prevent them on new messages.

    Turns out this isn't hard to START. (I love the code structure )

    I commented out those lines, and above I added:

    //STRIP ALL SIGNATURES (START WITH '--' ON A BLANK LINE)

    //USER SHOULD SET REPLY SEP TO --

    //THIS LOOKS FOR PATTERN ON A LINE BY ITSELF

    if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()) && strpos($var,"\n".$tag."\n"))

    list($var)=split("\n".$tag."\n",$var);

    ABOVE

    if(!$ticket){ //New tickets...

    For those who aren't as old as me, a double dash (--) on a new line by itself (no leading or trailing spaces, etc.) has long been a standard prefix for delimiting a signature. (Actually it might supposed to be no leading whitespace, one trailing whitespace?) It's quite well documented - here is an example:

    http://email.about.com/od/emailsignaturenetiquette/qt/Use_the_Standard_Email_Signature_Delimiter.htm(http://email.about.com/od/emailsignaturenetiquette/qt/Use_the_Standard_Email_Signature_Delimiter.htm)

    Old mailers scripts like "mailman" used to depend on it.

    SO HERE IS THE PROBLEM.

    The code above kind of works... BUT the message text it sees, has been trimmed BEFORE this point. If the goal is to fix this issue in the long run permanently, wouldn't it be a good idea to adopt standard signature detection and recommend that users suggest proper etticut to their users? I know it won't always happen, but it makes it an option.

    The trouble with the existing code is MINOR - an unintentional truncation of message can occur if a message line contains two dashes and only whitespace - which seems to get trimmed down to just the two dashes, which is the standard delimeter.

    In the meantime, this is a pretty good fix I think - does anyone see a problem?

    Thanks again for an excellent tool!

    m/

  • I made a few changes and incorporated your ideas...

    A little differently - it works without changing the ticket class.

    I look up the staff id from the sender's email, and then create a staff session object from which I have the ability to call the postResponse method directly.

    This method also shows some rough code I added at the bottom that allows embedding image attachments in outlook like email messages that post embedded images without specifying a disposition.

    It's ugly but it works.

    @@ -93,9 +96,29 @@

    $extid=trim(preg_replace("/", "", $regs));

    $ticket= new Ticket(Ticket:($extid));

    //Allow mismatched emails?? For now hell NO.

    - if(!is_object($ticket) || strcasecmp($ticket->getEmail(),$var))

    - $ticket=null;

    -}

    +//TO ALLOW MOD BELOW TO WORK

    +// if(!is_object($ticket) || strcasecmp($ticket->getEmail(),$var))

    +// $ticket=null;

    +}

    +// mod to allow staff to reply via email

    + // check that email address is in the staff list.

    + $sql="SELECT username,staff_id FROM " . STAFF_TABLE . " WHERE email='" . $var . "' ";

    + $query=db_query($sql);

    + while($row = mysql_fetch_array($query)) {

    + $senderUsername = $row;

    + $senderStaffID = $row;

    + }

    +//thisuser is a global required by postResponse

    + $thisuser = new StaffSession($senderStaffID);

    +

    + // if username is in the staff list (or original client), then it can be a reply

    + // if username is not in the staff list, then it must be a new ticket

    + if ((!$senderUsername)

    + && (!is_object($ticket) || strcasecmp($ticket->getEmail(),$var))

    + $ticket=null;

    + }

    +// end mod

    +

    $errors=array();

    $msgid=0;

    if(!$ticket){ //New tickets...

    @@ -110,9 +133,24 @@

    if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()) && strpos($var,$tag))

    list($message)=split($tag,$var);

    //post message....postMessage does the cleanup.

    +// mod to make a response from STAFF a response not a message

    +if (!$senderUsername){

    if(!($msgid=$ticket->postMessage($message,'Email',$var,$var))) {

    api_exit(EX_DATAERR,"Unable to post message \n\n $message\n");

    }

    +} else {

    +// function postResponse($msgid,$response,$signature='none',$attachment=false,$canalert=true){

    +// function postMessage($msg,$source='',$msgid=NULL,$headers='',$newticket=false){

    +$sql='SELECT MAX(msg_id) FROM '.TICKET_MESSAGE_TABLE.' WHERE ticket_id ='.$ticket->getId();

    +$query=db_query($sql);

    +while($row = mysql_fetch_array($query)) {

    + $Last_msg_id = $row;

    +}

    + if(!($msgid=$ticket->postResponse($Last_msg_id,$message))){

    + api_exit(EX_DATAERR,"Unable to post response \n\n $message\n");

    + }

    +}

    +// end mod

    }

    //Ticket created...save attachments if enabled.

    $struct=$parser->getStruct();

    @@ -122,6 +160,13 @@

    if($part->disposition

    && (!strcasecmp($part->disposition,'attachment') || !strcasecmp($part->disposition,'inline') || !strcasecmp($part->ctype_primary,'image'))){

    $filename=$part->d_parameters;

    + if($filename && $cfg->canUploadFileType($filename)) {

    + $ticket->saveAttachment($filename,$part->body,$msgid,'M');

    + }

    +//THIS PATCH ADDS THE ABILITY TO SAVE EMBEDDED IMAGES IN AN HTML EMAIL FROM OUTLOOK 2007

    + } elseif (!($part->disposition)

    + && (!strcasecmp($part->ctype_primary,'image')) ) {

    + $filename=$part->ctype_parameters;

    if($filename && $cfg->canUploadFileType($filename)) {

    $ticket->saveAttachment($filename,$part->body,$msgid,'M');

    }

  • In settings->email settings-> reply separator, use “-----Original Message-----“ to automatically strip replies generated by outlook

    I think this field should take more than one value… “do not edit below this line” might make sense for osticket generated messages, but we can’t force mail clients to use the same setting… if we could pick some standard ones we might hit the 80/20 rule

    What do you think?

  • File attachments… Our server uses a different user account for the mail server vs. the web server. This means scripts like the api pipe run with different permissions / owner / group.

    First, the upload folder needs to be accessible (write) by both web users AND mail user – in my case I made it 0777

    For security, this folder should NOT be inside the web root – that way people can not take advantage of the server as easily.

    The, patch the code to ensure attachments are editable / accessible by the other process (i.e. the web server can delete an attachment submitted by email):

    --- class.ticket.php.ORIGINAL Fri Mar 5 00 2010

    +++ class.ticket.php Fri Mar 5 00 2010

    @@ -832,6 +832,8 @@

    $file=Format:($file);

    $filename=rtrim($dir,'/').'/'.$rand.'_'.$file;

    if(move_uploaded_file($file,$filename)){

    +//FORCE CHMOD TO ENSURE READABLE / DELETEABLE BY ALL

    +chmod($filename, 0666);

    $sql ='INSERT INTO '.TICKET_ATTACHMENT_TABLE.' SET created=NOW() '.

    ',ticket_id='.db_input($this->getId()).

    ',ref_id='.db_input($refid).

    @@ -861,6 +863,8 @@

    if(($fp=fopen($filename,'w'))) {

    fwrite($fp,$data);

    fclose($fp);

    +//FORCE CHMOD TO ENSURE READABLE / DELETEABLE BY ALL

    +chmod($filename, 0666);

    $size=@filesize($filename);

    $sql ='INSERT INTO '.TICKET_ATTACHMENT_TABLE.' SET created=NOW() '.

    ',ticket_id='.db_input($this->getId()).

  • IN api FOLDER THIS PATCH FIXES EMBEDDED IMAGES AS ATTACHMENTS FROM OUTLOOK 2007

    The normal attachment logic looks for “disposition” and then tests it and ctype.

    THIS IS NOT ELLEGANT, not configurable in present form, and will not filter small images which would likely be signature images or backgrounds.

    But hopefully it will start someone on the right track. Maybe I’ll improve it later.

    --- pipe.php.ORIGINAL Thu Mar 4 23 2010

    +++ pipe.php Fri Mar 5 01 2010

    @@ -125,6 +125,13 @@

    if($filename && $cfg->canUploadFileType($filename)) {

    $ticket->saveAttachment($filename,$part->body,$msgid,'M');

    }

    +//THIS PATCH ADDS THE ABILITY TO SAVE EMBEDDED IMAGES IN AN HTML EMAIL FROM OUTLOOK 2007

    + } elseif (!($part->disposition)

    + && (!strcasecmp($part->ctype_primary,'image')) ) {

    + $filename=$part->ctype_parameters;

    + if($filename && $cfg->canUploadFileType($filename)) {

    + $ticket->saveAttachment($filename,$part->body,$msgid,'M');

    + }

    }

    }

    }