Annotation of sbbs/src/sbbs3/mime.c, revision 1.1

1.1     ! root        1: /* mime.c */
        !             2: 
        !             3: /* Synchronet MIME functions */
        !             4: 
        !             5: /* $Id: mime.c,v 1.7 2003/06/14 10:13:27 rswindell Exp $ */
        !             6: 
        !             7: /****************************************************************************
        !             8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
        !             9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
        !            10:  *                                                                                                                                                     *
        !            11:  * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html         *
        !            12:  *                                                                                                                                                     *
        !            13:  * This program is free software; you can redistribute it and/or                       *
        !            14:  * modify it under the terms of the GNU General Public License                         *
        !            15:  * as published by the Free Software Foundation; either version 2                      *
        !            16:  * of the License, or (at your option) any later version.                                      *
        !            17:  * See the GNU General Public License for more details: gpl.txt or                     *
        !            18:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
        !            19:  *                                                                                                                                                     *
        !            20:  * Anonymous FTP access to the most recent released source is available at     *
        !            21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
        !            22:  *                                                                                                                                                     *
        !            23:  * Anonymous CVS access to the development source and modification history     *
        !            24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
        !            25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
        !            26:  *     (just hit return, no password is necessary)                                                     *
        !            27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
        !            28:  *                                                                                                                                                     *
        !            29:  * For Synchronet coding style and modification guidelines, see                                *
        !            30:  * http://www.synchro.net/source.html                                                                          *
        !            31:  *                                                                                                                                                     *
        !            32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
        !            33:  * format) via e-mail to [email protected]                                                                      *
        !            34:  *                                                                                                                                                     *
        !            35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
        !            36:  ****************************************************************************/
        !            37: 
        !            38: /* See RFCs 1521,2045,2046,2047,2048,2049,1590 */
        !            39: 
        !            40: #include <stdlib.h>
        !            41: #include <stdio.h>
        !            42: #include <time.h>
        !            43: 
        !            44: #include "sbbs.h"
        !            45: #include "mailsrvr.h"
        !            46: #include "base64.h"
        !            47: 
        !            48: #define SIZEOF_MIMEBOUNDARY     36
        !            49: 
        !            50: char* mimegetboundary()
        !            51: {
        !            52:     int                i, num;
        !            53:     char*      boundaryString = (char*)malloc(SIZEOF_MIMEBOUNDARY + 1);
        !            54: 
        !            55:     srand(time(NULL));
        !            56:     if (boundaryString == NULL) 
        !            57:         return NULL;
        !            58:     for (i=0;i<SIZEOF_MIMEBOUNDARY;i++) {
        !            59:         num=(rand()%62);    
        !            60:         if(num<10)
        !            61:             num+=48;  
        !            62:         else if(num>=10 && num<36)
        !            63:             num+=55;
        !            64:         else
        !            65:             num+=61;
        !            66:         boundaryString[i]=(char)num;
        !            67:     }
        !            68:     boundaryString[i]='\0';
        !            69:     return boundaryString;
        !            70: }
        !            71: 
        !            72: void mimeheaders(SOCKET socket, char* boundary)
        !            73: {
        !            74:     sockprintf(socket,"MIME-Version: 1.0");
        !            75:     sockprintf(socket,"Content-Type: multipart/mixed;");
        !            76:     sockprintf(socket," boundary=\"%s\"",boundary);
        !            77: }
        !            78: 
        !            79: void mimeblurb(SOCKET socket, char* boundary)
        !            80: {
        !            81:     sockprintf(socket,"This is a multi-part message in MIME format.");
        !            82:     sockprintf(socket,"");
        !            83: }
        !            84: 
        !            85: void mimetextpartheader(SOCKET socket, char* boundary)
        !            86: {
        !            87:     sockprintf(socket,"--%s",boundary);
        !            88:     sockprintf(socket,"Content-Type: text/plain;");
        !            89:     sockprintf(socket," charset=\"iso-8859-1\"");
        !            90:     sockprintf(socket,"Content-Transfer-Encoding: 7bit");
        !            91: }
        !            92: 
        !            93: BOOL base64out(SOCKET socket, char* pathfile)
        !            94: {
        !            95:     FILE *  fp;
        !            96:     char    in[57];
        !            97:     char    out[77];
        !            98:     int     bytesread;
        !            99: 
        !           100:     if((fp=fopen(pathfile,"rb"))==NULL) 
        !           101:         return(FALSE);
        !           102:     while(1) {
        !           103:         bytesread=fread(in,1,sizeof(in),fp);
        !           104:                if((b64_encode(out,sizeof(out),in,bytesread)==-1)
        !           105:                                || !sockprintf(socket,out))  {
        !           106:                        fclose(fp);
        !           107:                        return(FALSE);
        !           108:                }
        !           109:         if(bytesread!=sizeof(in) || feof(fp))
        !           110:             break;
        !           111:     }
        !           112:        fclose(fp);
        !           113:     sockprintf(socket,"");
        !           114:        return(TRUE);
        !           115: }
        !           116: 
        !           117: BOOL mimeattach(SOCKET socket, char* boundary, char* pathfile)
        !           118: {
        !           119:     char* fname = getfname(pathfile);
        !           120: 
        !           121:     sockprintf(socket,"--%s",boundary);
        !           122:     sockprintf(socket,"Content-Type: application/octet-stream;");
        !           123:     sockprintf(socket," name=\"%s\"",fname);
        !           124:     sockprintf(socket,"Content-Transfer-Encoding: base64");
        !           125:     sockprintf(socket,"Content-Disposition: attachment;");
        !           126:     sockprintf(socket," filename=\"%s\"",fname);
        !           127:     sockprintf(socket,"");
        !           128:     if(!base64out(socket,pathfile))
        !           129:                return(FALSE);
        !           130:     sockprintf(socket,"");
        !           131:        return(TRUE);
        !           132: }
        !           133: 
        !           134: void endmime(SOCKET socket, char* boundary)
        !           135: {
        !           136:        /* last boundary */
        !           137:     sockprintf(socket,"--%s--",boundary);
        !           138:     sockprintf(socket,"");
        !           139: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.