⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sflmail.c

📁 短小精悍的C语言标准函数库。提供450个以上的可移植的算法和工具代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
       while (1)
         {
           getstrfld (smtp->strBinFiles, iCnt++, 0, ",;", strFile);
           trim (strFile);
           if (*strFile)
             {
               strcpy (strUUEFile, strFile);
               if (strchr (strUUEFile, '.'))
                   *((strchr (strUUEFile, '.')))= (char)NULL;
               strcat (strUUEFile, ".uue");
               uuencode (strFile, strUUEFile, smtp->strlast_smtp_message);
               fpin = fopen (strUUEFile, "rb");
               if (!fpin)
                 {
                   return -6;
                 }

               strcpy (strOut, "\r\n--Message-Boundary-21132\r\n");
               xstrcat (strOut,
                        "Content-Type: application/octet-stream; name=",
               getfilename (strFile), "\r\n", NULL);
               strcat (strOut, "Content-Transfer-Encoding: x-uuencode\r\n");
               xstrcat (strOut, "Content-Disposition: attachment; filename=",
                        getfilename (strFile), "\r\n\n", NULL);
               smtp_send_data (iSocket, strOut);
               while (!feof (fpin))
                 {
                   memset (strRetBuff, 0, 513);
                   fread (strRetBuff, sizeof (char), 512, fpin);
                   smtp_send_data (iSocket, strRetBuff);
                 }

               fclose (fpin);

               if ( !smtp->debug )
                  unlink (strUUEFile);
             }
           else
               break;
         }
     }

   /* This ends the message. */
   smtp_send_data (iSocket, ".\r\n");
   if (getreply (iSocket, smtp) > 400)
        return -7;

   /* Now log off the SMTP port. */
   smtp_send_data (iSocket, "QUIT\n");
   if (getreply (iSocket, smtp) > 400)
        return -8;

   /*
      Clean-up.
   */
   /* Close the port up. */
   close_socket (iSocket);

   /* If a clean send, then reset and leave. */
   ip_nonblock = iOld_ip_nonblock;

   return 0;
}

/*  ---------------------------------------------------------------------[<]-
    Function: smtp_send_mail

    Synopsis: Format and send a SMTP message, by calling the
    smtp_send_mail_ex function.  This function is kept to be compatable
    with previous versions of smtp_send_mail, smtp_send_mail_ex should
    now be used, this will be deleted soon.
    ---------------------------------------------------------------------[>]-*/

int smtp_send_mail (
   char *strSmtpServer,
   char *strMessageBody,
   char *strSubject,
   char *strSenderUserId,
   char *strFullSenderUserId,
   char *strDestUserIds,
   char *strFullDestUserIds,
   char *strCcUserIds,
   char *strFullCcUserIds,
   char *strBccUserIds,
   char *strFullBccUserIds,
   char *strRetPathUserId,
   char *strRrcpUserId,
   char *strMsgComment,
   char *strMailerName,
   char *strBinFiles,
   char *strTxtFiles,
   char *strDebugFile )
{
   SMTP smtp;

   smtp.strSmtpServer = strSmtpServer;
   smtp.strMessageBody = strMessageBody;
   smtp.strSubject = strSubject;
   smtp.strSenderUserId = strSenderUserId;
   smtp.strFullSenderUserId = strFullSenderUserId;
   smtp.strDestUserIds = strDestUserIds;
   smtp.strFullDestUserIds = strFullDestUserIds;
   smtp.strCcUserIds = strCcUserIds;
   smtp.strFullCcUserIds = strFullCcUserIds;
   smtp.strBccUserIds = strBccUserIds;
   smtp.strFullBccUserIds = strFullBccUserIds;
   smtp.strRetPathUserId = strRetPathUserId;
   smtp.strRrcpUserId = strRrcpUserId;
   smtp.strMsgComment = strMsgComment;
   smtp.strMailerName = strMailerName;
   smtp.strBinFiles = strBinFiles;
   smtp.strTxtFiles = strTxtFiles;
   smtp.connect_retry_cnt = 3;
   smtp.retry_wait_time = 0;
   smtp.debug = 0;
   smtp.strDebugFile = strDebugFile;

   return smtp_send_mail_ex (&smtp);
}

/*
 *  uuencode -- internal
 *
 *  Synopsis: Uuencode a file, with the output going to a new file. This
 *  function is used by smtp_send_mail.
 * -------------------------------------------------------------------------*/

static int uuencode (
   char *strIn,
   char *strOut,
   char *strlast_smtp_message)
{
   char strLine[46];
   int iCnt, iLineLen;
   FILE *fpin, *fpout;

   if (!(fpin = fopen (strIn, "rb")))
     {
       strcpy (strlast_smtp_message, strIn);
       return 1;
     }

   if (!(fpout = fopen (strOut, "wb")))
     {
       strcpy (strlast_smtp_message, "Could not create temp file for write.");
       return 1;
     }

   fprintf (fpout, "begin 666 %s\n", getfilename (strIn));

   while (1)
     {
       iLineLen = fread (strLine, sizeof (char), 45, fpin);
       if (iLineLen <= 0)
           break;

       fputc (ENC (iLineLen), fpout);

       for (iCnt = 0; iCnt < iLineLen; iCnt += 3)
         {
           putgroup (&strLine[iCnt], fpout);
         }

       fputc ('\n', fpout);
     }

   fprintf (fpout, "end\n");

   fclose (fpin);
   fclose (fpout);
   return 0;
}

/*
 *  putgroup -- internal
 *
 *  Synopsis: Write out 3 char group to uuendcoded file making it
 *  printable  This function is used by uuencode.
 * -------------------------------------------------------------------------*/

static void putgroup (
   char *strgroup,
   FILE *fp)
{
    int ichr1, ichr2, ichr3, ichr4;

    ichr1 =   strgroup [0] >> 2;
    ichr2 = ((strgroup [0] << 4) & 0x030) | ((strgroup [1] >> 4) & 0x00f);
    ichr3 = ((strgroup [1] << 2) & 0x03c) | ((strgroup [2] >> 6) & 0x003);
    ichr4 =   strgroup [2] & 0x03f;

    fputc (ENC (ichr1), fp);
    fputc (ENC (ichr2), fp);
    fputc (ENC (ichr3), fp);
    fputc (ENC (ichr4), fp);
}

/*
 *  getreply -- internal
 *
 *  Synopsis: Get a reply from the SMTP server and see thats it's not
 *  an error. This function is used by smtp_send_mail.
 * -------------------------------------------------------------------------*/

static int getreply (
   int iSocket,
   SMTP *smtp)
{
    int read_size;
    FILE *fpout;
    char strRetBuff[513];

    read_size = read_TCP ((sock_t)iSocket, strRetBuff, 512);
    /* See if we have not gotten a responce back from the mail server. */
    if (read_size == 0)
        return 777;
    else
        strRetBuff [read_size] = '\0';

    /* Save off server reply. */
    strcpy (smtp-> strlast_smtp_message, strRetBuff);
    trim (strRetBuff);
    strRetBuff [3] = '\0';

    if ( smtp->debug )
      {
        if ((fpout = fopen (smtp->strDebugFile, "a")))
          {
            fputs (smtp->strlast_smtp_message, fpout );
            fclose (fpout);
          }
      }
   return atoi (strRetBuff);
}

/*
 *  getfilename -- internal
 *
 *  Synopsis: Get's the name from the full path of a file. This function
 *  is used by smtp_send_mail.
 * -------------------------------------------------------------------------*/

static char *getfilename (
   char *strFullPath)
{
   int iLen;
   char *strTmp;

   iLen = strlen (strFullPath);
   strTmp = (strFullPath + iLen);
   while (1)
     {
       if (*strTmp == PATHEND || !iLen)
           break;
       strTmp--;
       iLen--;
     }

   if (*strTmp == PATHEND)
       strTmp++;

   return strTmp;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -