Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

# - Code to handle multiple blanks in a reply (quash several consecu… #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion wmbiff/wmbiff/tlsComm.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,35 @@ static int wait_for_it(int sd, int timeoutseconds)
return (FD_ISSET(sd, &readfds));
}

/* exported for testing */
/* This version converts sequence of multiple blanks into a single
* blank. This overcomes, say, the bug in the imap server of a random
* company who thinks it can disregard standards because it is big and
* hard. (pun intended) */
extern char *
strncpy_trim_blanks(char *dest, const char *src, size_t n)
{
size_t i;
int last_read_was_not_a_blank = 1;
char *m_src = src, *m_dest = dest;
char ch;

for (i = 0; i < n && src[i] != '\0'; i++) {
ch = *m_src++;

if (ch != ' ' || last_read_was_not_a_blank) {
*m_dest = ch;
m_dest++;
}

last_read_was_not_a_blank = ch != ' ';
}
for ( ; i < n; i++)
dest[i] = '\0';

return dest;
}

/* exported for testing */
extern int
getline_from_buffer(char *readbuffer, char *linebuffer, int linebuflen)
Expand All @@ -184,7 +213,7 @@ getline_from_buffer(char *readbuffer, char *linebuffer, int linebuflen)

if (i != 0) {
/* copy a line into the linebuffer */
strncpy(linebuffer, readbuffer, (size_t) i);
strncpy_trim_blanks(linebuffer, readbuffer, (size_t) i);
/* sigh, null terminate */
linebuffer[i] = '\0';
/* shift the rest over; this could be done
Expand Down