Logo Search packages:      
Sourcecode: nbsmtp version File versions  Download package

int smtp_write_data ( servinfo_t serverinfo,
char *  msg,
int  length 
)

Writes data to the socket (actually it writes the message body and headers).

Parameters:
[in] serverinfo A pointer to a servinfo_t structure with the information needed
[in] msg A pointer to the buffer with the message
[in] length An integer with the number of bytes to be written
Returns:
1 in case of error, 0 if everything goes allright

Definition at line 142 of file smtp.c.

References fd_putc().

Referenced by nbsmtp_data().

{
      char *p;
      int i = 0; /* Avoid segfault if msg[0]=='\n' or msg[0]=='.' */
      char r = '\r';
      char dot = '.';

      for ( p = msg ; *p && i < length; p++ )
      {
            if (*p=='\n')
            {
                  if (i>0 && *(p-1)!='\r')
                  {
                        if (fd_putc(serverinfo,&r)<1)
                        {
                              return 1;
                        }
                  }
                  else if (i==0)
                  {
                        if (fd_putc(serverinfo,&r)<1)
                        {
                              return 1;
                        }
                  }
            }
            else if (*p=='.' && i>0 && *(p-1)=='\n')
            {
                  if (fd_putc(serverinfo,&dot)<1)
                  {
                        return 1;
                  }
            }

            if (fd_putc(serverinfo,p)<1)
            {
                  return 1;
            }

            i++;
      }

      return 0;
}


Generated by  Doxygen 1.6.0   Back to index