Author Topic: Images Not Displayed Properly  (Read 3495 times)

Offline swatts

  • Newbie
  • *
  • Posts: 2
Images Not Displayed Properly
« on: July 23, 2008, 04:12:21 PM »
When I receive emails with images attached clicking on the image gives a broken image in the browser. If I download the image the image is invalid in a graphics viewer.

RoundCube is executing:

http://vader/rcube/?_task=mail&_action=get&_mbox=INBOX&_uid=854&_part=2

When I check the source of the email I see:

Content-Type: multipart/mixed; boundary="=_49fcd68533a14cbefec6082f6f0b0306"
...More headers....

--=_49fcd68533a14cbefec6082f6f0b0306
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Blah blah

--=_49fcd68533a14cbefec6082f6f0b0306
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="DSC00063.JPG"

/9j/4XMqRXhpZgAATU0AKgAAAAgACgEPAAIAAAAOAAACJAEQAAIAAAAGAAACMgESAAMAAAABAAEA
AAEaAAUAAAABAAACOAEbAAUAAAABAAACQAEoAAMAAAABAAIAAAExAAIAAAApAAACSAEyAAIAAAAU
AAACcgITAAMAAAABAAIAAIdpAAQAAAABAAAAhgAAAcoAGIKaAAUAAAABAAAChoKdAAUAAAABAAAC
jognAAMAAAABAGQAAJAAAAcAAAAEMDIyMJADAAIAAAAUAAAClpAEAAIAAAAUAAACqpEBAAcAAAAE

When I do a hex dump of the file DSC00063.JPG sent and what RoundCube downloads/displays I can see RoundCube is inserting an extra /n at the start of the image file.

I am using 0.1.1. Is this a problem with the MIME handling?

-Steve

Offline swatts

  • Newbie
  • *
  • Posts: 2
Fixed :-)
« Reply #1 on: July 25, 2008, 01:24:34 PM »
Okay I have fixed the issue of attached mime content (images, pdfs, excel etc) not showing or displaying as junk.

Checking the files an extra 0A (\n) linefeed character was being inserted at the start of the attached files, making them corrupt for the applications which try to view them, or indeed the web browser.

Debugging the code, it appears that the PHP function header() is responsible for inserting the extra 0A character.

To fix this I put a work around in program/steps/mail/get.inc.

Around line 64 I inserted ob_start(); before the first call to headers():

ob_start();
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

And then around line 114 I added ob_end_clean() and ob_clean() after the last call to headers():

      header(sprintf('Content-Disposition: %s; filename="%s";',
                     $_GET['_download'] ? 'attachment' : 'inline',
                     $part->filename ? abbreviate_string($part->filename, 55) : "roundcube.$ctype_secondary"));
ob_end_clean();
ob_clean();

Attached images now display okay inline, and can be downloaded okay without the extra 0A causing applications not to handle the file correctly.

Trawling the net there are few mentions of issues of bugs in PHP headers() but most of these are dismissed as being caused by other factors such as empty php lines. (Well I could not find an empty php line - and my roundcube php is pure 0.1.1 with no mods. Nor could I find ANY Cannot modify header information - headers already sent in in the error logs)

Anyway adding the exta ob_* calls worked for me. Hope it works for others.

And maybe someone more knowledgeable can explain why it is necessary.

-Steve
« Last Edit: July 25, 2008, 04:11:27 PM by swatts »

Offline William

  • Newbie
  • *
  • Posts: 5
Images Not Displayed Properly
« Reply #2 on: August 29, 2008, 06:41:28 PM »
Greetings

Which version of r/cube does your fix apply to?

I'm not a php dev, but I can do the "monkey see, monkey do" thing given enough info :)

Cheers
-- William

Offline dan22

  • Newbie
  • *
  • Posts: 1
Thanks for the quick fix
« Reply #3 on: August 30, 2008, 08:23:05 AM »
I installed 0.1.1 the other day and just noticed the problem with attachments not showing up correctly. I made the changes you posted and had the fix implemented in under a minute.

Thanks again,

Offline William

  • Newbie
  • *
  • Posts: 5
Images Not Displayed Properly
« Reply #4 on: August 30, 2008, 08:52:45 AM »
Hello Dan

Quote from: dan22;13594
I installed 0.1.1 ,


How is that working out for you?  after a disasterous attempt (probably PHP rather than r/cube probs) with the latest release I've reverted to 0.1-stable.

Quote from: dan22;13594
... the problem with attachments not showing up correctly. I made the changes you posted and had the fix implemented in under a minute.


Encouraged by your post I did the same - no change :(

Oh well.

-- WNT