Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

email.cc

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001 James Hess
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the authors nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00043 #include <stdio.h>
00044 #include <stdlib.h>
00045 #include <string.h>
00046 
00047 #include "email.h"
00048 #include "options.h"
00049 
00059 const char *EmailString::set_string(const char *str)
00060 {
00061     int len;
00062 
00063     if (theString)
00064         delete theString;
00065     if (!str)
00066         return (theString = NULL);
00067 
00068     theString = new char[(len = strlen(str)) + 1];
00069     strcpy(theString, str);
00070     theLength = 0;
00071 
00072     if (!theString) {
00073         fprintf(stderr, "Out of memory!\n");
00074         abort();
00075         return theString;
00076     }
00077     theLength = len;
00078     return theString;
00079 }
00080 
00086 const char *EmailString::add(const char *str)
00087 {
00088     int len;
00089 
00090     if (!str)
00091         return NULL;
00092     len = strlen(str);
00093 
00094     if (!theString) {
00095         theString = new char[len + 1];
00096         if (!theString) {
00097             fprintf(stderr, "Out of memory!\n");
00098             abort();
00099             return str;
00100         }
00101         strcpy(theString, str);
00102         theLength = len;
00103         return str;
00104     }
00105 
00106     theString =
00107         static_cast<char *>(realloc(theString, len + theLength + 1));
00108     strcat(theString + theLength, str);
00109     theLength += len;
00110     return theString;
00111 }
00112 
00119 const char *EmailAddressBuf::add_email(const char *str)
00120 {
00121     int len;
00122 
00123     if (!str)
00124         return NULL;
00125     len = strlen(str);
00126 
00127     if (!theString) {
00128         theString = new char[len + 1];
00129         if (!theString) {
00130             fprintf(stderr, "Out of memory!\n");
00131             abort();
00132             return str;
00133         }
00134         strcpy(theString, str);
00135         theLength = len;
00136         return str;
00137     }
00138 
00139     theString =
00140         static_cast<char *>(realloc(theString, len + theLength + 3));
00141     strcat(theString + theLength, ", ");
00142     strcat(theString + theLength + 2, str);
00143     theLength += len + 2;
00144     return theString;
00145 }
00146 
00147 
00154 void EmailMessage::send()
00155 {
00156     FILE *p;
00157 
00158     if (!to.get_string() || !from.get_string() || !body.get_string()) {
00159         fprintf(stderr, "EmailMessage::send(): Failed.");
00160         return;
00161     }
00162 
00163     p = popen(SENDMAIL, "w");
00164     if (p == NULL)
00165         return;
00166 
00167     fprintf(p, "To: %s\n"
00168                "From: %s\n"
00169                "Subject: %s\n",
00170     to.get_string(), from.get_string(), subject.get_string()? subject.
00171     get_string() : "[services] No subject");
00172 
00173     fputs(body.get_string(), p);
00174     fflush(p);
00175     pclose(p);
00176 }

Generated at Sat Oct 25 20:56:07 2003 for Services using Doxygen.
Services Copyr. 1996-2001 Chip Norkus, Max Byrd, Greg Poma, Michael Graff, James Hess, Dafydd James. All rights reserved See LICENSE for licensing information.