1

I have an Android app where a user can ask a question. This question is sent to a server which in turn sends it to my e-mail. I respond to the question and the response gets sent back to the server. The response is stored in a MySQL database. The user will poll the server and have the response pulled down onto their phone when it becomes available. When the response is displayed on the phone, the formatting is not right. There are special characters and extra whitespace displaying.

Here is an example of a response when it is sent to the server and placed in the database:

We live in a profit-driven society and the greater good of the people as a whole tends to get thrown to the wayside in favor of increasing one's wealth. Capitalism will not function the way it's intended to when morals are left behind.

When politicians step up to the plate they often aren't batting for the common people, but the highest bidder. It's the lobbyist representing a major corporation or some special interest group who will persuade a politician, through a financial contribution, to put their interests ahead of the interests of the general public. It's favoritism and crony capitalism at its best.

Do I feel the day will come where we'll rise beyond this? I would love to believe so, but at times it feels our current way of life has a stranglehold on us. Whether it be fear or the general lack of critical thinking that keeps people from pursuing the world/society we should have, something must change. We either will hit a breaking point and make our move or this system will continue to operate the way it does. I'll leave you with a famous quote from Edmund Burke, "The only thing necessary for the triumph of evil is that good men do nothing."

Here is what it looks like after it has been pulled down onto a phone(I shortened the misformatted response but the rest of it looks just like this part of it):

We live in a profit-driven society
and the greater good of the people
as a w=
hole tends to get thrown to the
wayside in favor of increasing one's
wealth.=
Capitalism will not function the
way its intended to when morals
are left b=
ehind.

When politicians step up to the plate
they often aren't batting for the
comm=
on people, but the highest bidder.

I do this before the response goes into the database:

$message = $dbhandler->real_escape_string($_POST["message"]);

When I create the table with the column that holds the response I assign the column the TEXT field.

I don't understand what's happening to the response either when its placed into the database or pulled from it. It has those equals signs and extra whitespace in it. Can somebody shed some light on this and offer up a remedy?

EDIT

I retrieve the response from the database like this:

$response = $dbhandler->query("SELECT response FROM qar WHERE id='$rowId'");

$row = $response->fetch_row();
if($row[0] != NULL) {
    echo($row[0]);
}
Red
  • 13
  • 5
  • So basically something is breaking it to make it fit on the screen (if u check the strings it ends with the same length)? what is the code you use to retrieve the data? – Prix Aug 24 '13 at 03:46

1 Answers1

1

The answer you're looking for is in your question itself:

This question is sent to a server which in turn sends it to my e-mail.

Sign onto your favourite terminal and run the following command for each block of and observe the output:

$ echo -en "We live in a profit-driven society and the greater good of the people as a w" | wc -c
76
$ echo -en "hole tends to get thrown to the wayside in favor of increasing one's wealth." | wc -c
76
$ echo -en "\nCapitalism will not function the way its intended to when morals are left b" | wc -c
76

See the pattern?

This occurs because your email uses a quoted-printable encoding which splits each line at 76 characters and uses an '=' character to indicate a line continuation. (Among other things.)

You have multiple alternatives:

  • Encode/decode the quoted-printable body yourself.
  • Use alternative email encoding instead of quoted-printable (base64 works well)
  • Manually split the lines of your quoted-printable email body before they go beyond 76 character line limit.
jmkeyes
  • 3,751
  • 17
  • 20