/********************************************************************** * PTlink IRC Services is (C) CopyRight PTlink IRC Software 1999-2006 * * http://software.pt-link.net * * This program is distributed under GNU Public License * * Please read the file COPYING for copyright information. * ********************************************************************** Description: email functions */ #include "module.h" #include "dbconf.h" #include "path.h" /* ETCPATH */ #define EMAIL #include "email.h" SVS_Module mod_info = /* module, version, description */ {"email", "1.2", "just an email module" }; /* Change Log 1.1 - #44: invalid string on email sender */ /** functions/events we require **/ /* void (*FunctionPointer)(void);*/ MOD_REQUIRES MOD_FUNC(dbconf_get_or_build) MOD_END /** functions/events we provide **/ /* void my_function(void); */ MOD_PROVIDES EMAIL_FUNCTIONS MOD_END static char* EmailFrom; static char* EmailFromName; DBCONF_PROVIDES DBCONF_WORD(EmailFrom,"noreply@pt-link.net", "Email address to be used on the From: field for services emails") DBCONF_STR(EmailFromName, "PTlink IRC Services", "Name to be used on the From: field for services emails") DBCONF_END /** Internal functions declaration **/ /* void internal_function(void); */ /** Local variables **/ static int symcount = 0; /* count of stored symbols */ static char* symbol_names[32]; static char* symbol_data[32]; /** rehash code **/ int mod_rehash(void) { if(dbconf_get_or_build(mod_info.name, dbconf_provides) < 0 ) { errlog("Error reading dbconf!"); return -1; } return 0; } /** load code **/ int mod_load(void) { #ifndef SENDMAIL errlog( "sendmail client was not found during configure, email functios are disabled!"); #endif return 0; } /** unload code **/ void mod_unload(void) { return; } /** internal functions implementation starts here **/ /* free memory allocated for the email templates */ void email_free(char **emails) { int i; for(i=0; i sizeof(buf)) { errlog("Trying to send email too big!"); return -1; } /* build new buffer applying symbols replacement */ s = msg; t = buf; while(*s && ( t-buf < sizeof(buf) )) { if(*s == '%') { char *symbol; ++s; symbol = s; while(*s && *s !='%') ++s; if(*s == '%') { *s = '\0'; if(strcasecmp(symbol, "from") == 0) t += snprintf(t, sizeof(buf)-(t-buf), "%s", EmailFrom); else if(strcasecmp(symbol, "from_name") == 0) t += snprintf(t, sizeof(buf)-(t-buf), "%s", EmailFromName); else t += snprintf(t, sizeof(buf)-(t-buf), "%s", email_symbol(symbol)); *s = '%'; } } else *(t++) = *s; ++s; } *t = '\0'; if (!(p = popen(sendmail, "w"))) { errlog("ERROR, could not popen on email_send()"); return -1; } fprintf(p, "%s", buf); pclose(p); return 0; } /* * initialize the symbols list */ void email_init_symbols(void) { symcount = 0; } /* * adds a symbol to the symbols list */ void email_add_symbol(char *name, char* value) { symbol_names[symcount] = name; symbol_data[symcount] = value; ++symcount; } /* * returns the value of a symbol */ char* email_symbol(char *name) { int i; for(i = 0; i < symcount; ++i) { if(strcmp(name, symbol_names[i]) == 0) return symbol_data[i]; } return ""; } /* End of module */