src/mail.c File Reference

#include "copyright.h"
#include "config.h"
#include <sys/time.h>
#include <sys/types.h>
#include "db.h"
#include "interface.h"
#include "attrs.h"
#include "externs.h"
#include "mail.h"
#include "alloc.h"
#include "htab.h"

Include dependency graph for mail.c:

Go to the source code of this file.

Data Structures

struct  malias

Defines

#define MALIAS_LEN   100

Functions

char * getstring_noalloc (FILE *, int)
void init_match (dbref player, const char *name, int type)
void match_absolute (void)
dbref match_result (void)
void putstring (FILE *f, const char *s)
int do_convtime (char *str, struct tm *ttm)
static int sign (int)
static void do_mail_flags (dbref, char *, mail_flag, int)
static void send_mail (dbref, dbref, const char *, const char *, int, mail_flag, int)
static int player_folder (dbref)
static int parse_msglist (char *, struct mail_selector *, dbref)
static int mail_match (struct mail *, struct mail_selector, int)
static int parse_folder (dbref, char *)
static char * status_chars (struct mail *)
static char * status_string (struct mail *)
void add_folder_name (dbref, int, char *)
static int get_folder_number (dbref, char *)
void check_mail (dbref, int, int)
static char * get_folder_name (dbref, int)
static char * mail_list_time (const char *)
static char * make_numlist (dbref, char *)
static char * make_namelist (dbref, char *)
static void mail_to_list (dbref, char *, char *, char *, int, int)
static void do_edit_msg (dbref, char *, char *)
static void do_mail_proof (dbref)
void do_mail_cc (dbref, char *)
void do_expmail_abort (dbref)
static void mail_db_grow (int newtop)
static void make_mail_freelist ()
static int add_mail_message (dbref player, char *message)
static int add_mail_message_nosig (char *message)
static void new_mail_message (char *message, int number)
static INLINE void add_count (int number)
static void delete_mail_message (int number)
INLINE char * get_mail_message (int number)
char * upcasestr (char *)
void do_mail_change_folder (dbref player, char *fld, char *newname)
void do_mail_tag (dbref player, char *msglist)
void do_mail_safe (dbref player, char *msglist)
void do_mail_clear (dbref player, char *msglist)
void do_mail_untag (dbref player, char *msglist)
void do_mail_unclear (dbref player, char *msglist)
void do_mail_file (dbref player, char *msglist, char *folder)
void do_mail_read (dbref player, char *msglist)
void do_mail_retract (dbref player, char *name, char *msglist)
void do_mail_review (dbref player, char *name, char *msglist)
void do_mail_list (dbref player, char *msglist, int sub)
void do_mail_purge (dbref player)
void do_mail_fwd (dbref player, char *msg, char *tolist)
mailmail_fetch (dbref player, int num)
void count_mail (dbref player, int folder, int *rcount, int *ucount, int *ccount)
void urgent_mail (dbref player, int folder, int *ucount)
void do_mail_nuke (dbref player)
void do_mail_debug (dbref player, char *action, char *victim)
void do_mail_stats (dbref player, char *name, int full)
void do_mail_stub (dbref player, char *arg1, char *arg2)
void do_mail (dbref player, dbref cause, int key, char *arg1, char *arg2)
int dump_mail (FILE *fp)
int load_mail (FILE *fp)
void set_player_folder (dbref player, int fnum)
void check_mail_expiration ()
void do_malias_switch (dbref player, char *a1, char *a2)
void do_malias (dbref player, dbref cause, int key, char *arg1, char *arg2)
void do_malias_send (dbref player, char *tolist, char *listto, char *subject, int number, mail_flag flags, int silent)
maliasget_malias (dbref player, char *alias)
void do_malias_create (dbref player, char *alias, char *tolist)
void do_malias_list (dbref player, char *alias)
void do_malias_list_all (dbref player)
void load_malias (FILE *fp)
void save_malias (FILE *fp)
void malias_read (FILE *fp)
void malias_write (FILE *fp)
void do_expmail_start (dbref player, char *arg, char *subject)
void do_mail_quick (dbref player, char *arg1, char *arg2)
void do_expmail_stop (dbref player, int flags)
void do_prepend (dbref player, dbref cause, int key, char *text)
void do_postpend (dbref player, dbref cause, int key, char *text)
void do_malias_desc (dbref player, char *alias, char *desc)
void do_malias_chown (dbref player, char *alias, char *owner)
void do_malias_add (dbref player, char *alias, char *person)
void do_malias_remove (dbref player, char *alias, char *person)
void do_malias_rename (dbref player, char *alias, char *newname)
void do_malias_delete (dbref player, char *alias)
void do_malias_adminlist (dbref player)
void do_malias_status (dbref player)

Variables

char msgbuff [LBUF_SIZE+(LBUF_SIZE >> 1)+1]
int ma_size = 0
int ma_top = 0
malias ** malias


Define Documentation

#define MALIAS_LEN   100

Definition at line 55 of file mail.c.

Referenced by do_malias_create().


Function Documentation

static INLINE void add_count ( int  number  )  [static]

Definition at line 225 of file mail.c.

References mail_entry::count, statedata::mail_list, and mudstate.

Referenced by load_mail(), and send_mail().

00226 {
00227         mudstate.mail_list[number].count++;
00228 }

void add_folder_name ( dbref  ,
int  ,
char *   
)

Definition at line 1666 of file mail.c.

References A_MAILFOLDERS, AF_LOCK, AF_MDARK, AF_NOPROG, AF_WIZARD, alloc_lbuf, atr_add(), atr_get(), free_lbuf, replace_string(), safe_str, string_match(), StringCopy, and upcasestr().

Referenced by do_mail_change_folder().

01667 {
01668         char *old, *res, *r, *atrstr;
01669         char *new, *pat, *str, *tbuf;
01670         int aflags;
01671 
01672         /*
01673          * Muck with the player's MAILFOLDERS attrib to add a string of the * 
01674          * 
01675          * *  * * form: number:name:number to it, replacing any such string
01676          * with a  *  * * * matching number. 
01677          */
01678 
01679         new = alloc_lbuf("add_folder_name.new");
01680         pat = alloc_lbuf("add_folder_name.pat");
01681         str = alloc_lbuf("add_folder_name.str");
01682         tbuf = alloc_lbuf("add_folder_name.tbuf");
01683 
01684         sprintf(new, "%d:%s:%d ", fld, upcasestr(name), fld);
01685         sprintf(pat, "%d:", fld);
01686         /*
01687          * get the attrib and the old string, if any 
01688          */
01689         old = NULL;
01690 
01691         atrstr = atr_get(player, A_MAILFOLDERS, &player, &aflags);
01692         if(*atrstr) {
01693                 StringCopy(str, atrstr);
01694                 old = (char *) string_match(str, pat);
01695         }
01696         if(old && *old) {
01697                 StringCopy(tbuf, str);
01698                 r = old;
01699                 while (!isspace(*r))
01700                         r++;
01701                 *r = '\0';
01702                 res = (char *) replace_string(old, new, tbuf);
01703         } else {
01704                 r = res = alloc_lbuf("mail_folders");
01705                 if(*atrstr)
01706                         safe_str(str, res, &r);
01707                 safe_str(new, res, &r);
01708                 *r = '\0';
01709         }
01710         /*
01711          * put the attrib back 
01712          */
01713         atr_add(player, A_MAILFOLDERS, res, player,
01714                         AF_MDARK | AF_WIZARD | AF_NOPROG | AF_LOCK);
01715         free_lbuf(str);
01716         free_lbuf(pat);
01717         free_lbuf(new);
01718         free_lbuf(tbuf);
01719         free_lbuf(atrstr);
01720         free_lbuf(res);
01721 }

static int add_mail_message ( dbref  player,
char *  message 
) [static]

Definition at line 148 of file mail.c.

References A_SIGNATURE, alloc_lbuf, atr_get(), EV_EVAL, EV_FCHECK, EV_NO_COMPRESS, EV_STRIP, exec(), free_lbuf, mail_db_grow(), statedata::mail_freelist, statedata::mail_list, make_mail_freelist(), mail_entry::message, mudstate, notify, number, and tprintf().

Referenced by do_malias_send(), and mail_to_list().

00149 {
00150         int number;
00151 
00152         char *atrstr, *execstr, *msg, *bp, *str;
00153         int aflags;
00154         dbref aowner;
00155 
00156         if(!strcasecmp(message, "clear")) {
00157                 notify(player,
00158                            "MAIL: You probably don't wanna send mail saying 'clear'.");
00159                 return -1;
00160         }
00161         if(!mudstate.mail_list) {
00162                 mail_db_grow(1);
00163         }
00164         /*
00165          * Add an extra bit of protection here 
00166          */
00167         while (mudstate.mail_list[mudstate.mail_freelist].message != NULL) {
00168                 make_mail_freelist();
00169         }
00170         number = mudstate.mail_freelist;
00171 
00172         atrstr = atr_get(player, A_SIGNATURE, &aowner, &aflags);
00173         execstr = bp = alloc_lbuf("add_mail_message");
00174         str = atrstr;
00175         exec(execstr, &bp, 0, player, player, EV_STRIP | EV_FCHECK | EV_EVAL,
00176                  &str, (char **) NULL, 0);
00177         *bp = '\0';
00178         msg = bp = alloc_lbuf("add_mail_message.2");
00179         str = message;
00180         exec(msg, &bp, 0, player, player, EV_EVAL | EV_FCHECK | EV_NO_COMPRESS,
00181                  &str, (char **) NULL, 0);
00182         *bp = '\0';
00183 
00184         mudstate.mail_list[number].message =
00185                 (char *) strdup(tprintf("%s %s", msg, execstr));
00186         free_lbuf(atrstr);
00187         free_lbuf(execstr);
00188         free_lbuf(msg);
00189         make_mail_freelist();
00190         return number;
00191 }

static int add_mail_message_nosig ( char *  message  )  [static]

Definition at line 197 of file mail.c.

References mail_db_grow(), statedata::mail_freelist, statedata::mail_list, make_mail_freelist(), mail_entry::message, mudstate, and number.

Referenced by load_mail().

00198 {
00199         int number;
00200 
00201         number = mudstate.mail_freelist;
00202         if(!mudstate.mail_list) {
00203                 mail_db_grow(1);
00204         }
00205         mudstate.mail_list[number].message = (char *) strdup(message);
00206 
00207         make_mail_freelist();
00208         return number;
00209 }

void check_mail ( dbref  ,
int  ,
int   
)

Definition at line 2205 of file mail.c.

References count_mail(), get_folder_name(), notify, notify_printf(), and urgent_mail().

Referenced by do_mail_change_folder(), and record_login().

02206 {
02207 
02208         /*
02209          * Check for new @mail 
02210          */
02211         int rc;                                         /*
02212 
02213                                                                  * read messages 
02214                                                                  */
02215         int uc;                                         /*
02216 
02217                                                                  * unread messages 
02218                                                                  */
02219         int cc;                                         /*
02220 
02221                                                                  * cleared messages 
02222                                                                  */
02223         int gc;                                         /*
02224 
02225                                                                  * urgent messages 
02226                                                                  */
02227 
02228         /*
02229          * just count messages 
02230          */
02231         count_mail(player, folder, &rc, &uc, &cc);
02232         urgent_mail(player, folder, &gc);
02233 #ifdef MAIL_ALL_FOLDERS
02234         notify_printf(player,
02235                                   "MAIL: %d messages in folder %d [%s] (%d unread, %d cleared).\r\n",
02236                                   rc + uc, folder, get_folder_name(player, folder), uc, cc);
02237 #else
02238         if(rc + uc > 0)
02239                 notify_printf(player,
02240                                           "MAIL: %d messages in folder %d [%s] (%d unread, %d cleared).",
02241                                           rc + uc, folder, get_folder_name(player, folder), uc,
02242                                           cc);
02243         else if(!silent)
02244                 notify(player, "\r\nMAIL: You have no mail.\r\n");
02245         if(gc > 0)
02246                 notify_printf(player,
02247                                           "URGENT MAIL: You have %d urgent messages in folder %d [%s].",
02248                                           gc, folder, get_folder_name(player, folder));
02249 #endif
02250         return;
02251 }

void check_mail_expiration ( void   ) 

Definition at line 2101 of file mail.c.

References delete_mail_message(), do_convtime(), M_Safe, confdata::mail_expiration, statedata::mail_htab, MAIL_ITER_SAFE, mudconf, mudstate, mail::next, nhashrepl(), mail::number, mail::prev, mail::subject, time(), mail::time, mail::to, and mail::tolist.

Referenced by fork_and_dump().

02102 {
02103         struct mail *mp, *nextp;
02104         struct tm then_tm = { 0 };
02105         time_t then, now = time(0);
02106         time_t expire_secs = mudconf.mail_expiration * 86400;
02107         dbref thing;
02108 
02109         /*
02110          * negative values for expirations never expire 
02111          */
02112         if(0 > mudconf.mail_expiration)
02113                 return;
02114 
02115         MAIL_ITER_SAFE(mp, thing, nextp) {
02116                 if(do_convtime((char *) mp->time, &then_tm)) {
02117                         then = timelocal(&then_tm);
02118                         if(((now - then) > expire_secs) && !(M_Safe(mp))) {
02119                                 /*
02120                                  * Delete this one 
02121                                  */
02122                                 /*
02123                                  * head and tail of the list are special 
02124                                  */
02125                                 if(mp->prev == NULL)
02126                                         nhashrepl((int) mp->to, (int *) mp->next,
02127                                                           &mudstate.mail_htab);
02128                                 else if(mp->next == NULL)
02129                                         mp->prev->next = NULL;
02130                                 /*
02131                                  * relink the list 
02132                                  */
02133                                 if(mp->prev != NULL)
02134                                         mp->prev->next = mp->next;
02135                                 if(mp->next != NULL)
02136                                         mp->next->prev = mp->prev;
02137                                 /*
02138                                  * save the pointer 
02139                                  */
02140                                 nextp = mp->next;
02141                                 /*
02142                                  * then wipe 
02143                                  */
02144                                 free((char *) mp->subject);
02145                                 delete_mail_message(mp->number);
02146                                 free((char *) mp->tolist);
02147                                 free((char *) mp->time);
02148                                 free(mp);
02149                         } else
02150                                 nextp = mp->next;
02151                 } else
02152                         nextp = mp->next;
02153         }
02154 }

void count_mail ( dbref  player,
int  folder,
int *  rcount,
int *  ucount,
int *  ccount 
)

Definition at line 884 of file mail.c.

References Cleared, Folder, statedata::mail_htab, mudstate, mail::next, nhashfind(), and Read.

Referenced by check_mail(), and fun_mail().

00886 {
00887         struct mail *mp;
00888         int rc, uc, cc;
00889 
00890         cc = rc = uc = 0;
00891         for(mp = (struct mail *) nhashfind((int) player, &mudstate.mail_htab);
00892                 mp; mp = mp->next) {
00893                 if(Folder(mp) == folder) {
00894                         if(Read(mp))
00895                                 rc++;
00896                         else
00897                                 uc++;
00898 
00899                         if(Cleared(mp))
00900                                 cc++;
00901                 }
00902         }
00903         *rcount = rc;
00904         *ucount = uc;
00905         *ccount = cc;
00906 }

static void delete_mail_message ( int  number  )  [static]

Definition at line 235 of file mail.c.

References mail_entry::count, statedata::mail_list, mail_entry::message, and mudstate.

Referenced by check_mail_expiration(), do_mail_debug(), do_mail_nuke(), do_mail_purge(), do_mail_retract(), get_mail_message(), and send_mail().

00236 {
00237         mudstate.mail_list[number].count--;
00238 
00239         if(mudstate.mail_list[number].count < 1) {
00240                 free(mudstate.mail_list[number].message);
00241                 mudstate.mail_list[number].message = NULL;
00242                 mudstate.mail_list[number].count = 0;
00243         }
00244 }

int do_convtime ( char *  str,
struct tm *  ttm 
)

Definition at line 732 of file functions.c.

00733 {
00734         char *buf, *p, *q;
00735         int i;
00736 
00737         if(!str || !ttm)
00738                 return 0;
00739         while (*str == ' ')
00740                 str++;
00741         buf = p = alloc_sbuf("do_convtime");    /*
00742                                                                                          * make a temp copy of arg 
00743                                                                                          */
00744         safe_sb_str(str, buf, &p);
00745         *p = '\0';
00746 
00747         get_substr(buf, p);                     /*
00748                                                                  * day-of-week or month 
00749                                                                  */
00750         if(!p || strlen(buf) != 3) {
00751                 free_sbuf(buf);
00752                 return 0;
00753         }
00754         for(i = 0; (i < 12) && string_compare(monthtab[i], p); i++);
00755         if(i == 12) {
00756                 get_substr(p, q);               /*
00757                                                                  * month 
00758                                                                  */
00759                 if(!q || strlen(p) != 3) {
00760                         free_sbuf(buf);
00761                         return 0;
00762                 }
00763                 for(i = 0; (i < 12) && string_compare(monthtab[i], p); i++);
00764                 if(i == 12) {
00765                         free_sbuf(buf);
00766                         return 0;
00767                 }
00768                 p = q;
00769         }
00770         ttm->tm_mon = i;
00771 
00772         get_substr(p, q);                       /*
00773                                                                  * day of month 
00774                                                                  */
00775         if(!q || (ttm->tm_mday = atoi(p)) < 1 || ttm->tm_mday > daystab[i]) {
00776                 free_sbuf(buf);
00777                 return 0;
00778         }
00779         p = (char *) index(q, ':');     /*
00780                                                                  * hours 
00781                                                                  */
00782         if(!p) {
00783                 free_sbuf(buf);
00784                 return 0;
00785         }
00786         *p++ = '\0';
00787         if((ttm->tm_hour = atoi(q)) > 23 || ttm->tm_hour < 0) {
00788                 free_sbuf(buf);
00789                 return 0;
00790         }
00791         if(ttm->tm_hour == 0) {
00792                 while (isspace(*q))
00793                         q++;
00794                 if(*q != '0') {
00795                         free_sbuf(buf);
00796                         return 0;
00797                 }
00798         }
00799         q = (char *) index(p, ':');     /*
00800                                                                  * minutes 
00801                                                                  */
00802         if(!q) {
00803                 free_sbuf(buf);
00804                 return 0;
00805         }
00806         *q++ = '\0';
00807         if((ttm->tm_min = atoi(p)) > 59 || ttm->tm_min < 0) {
00808                 free_sbuf(buf);
00809                 return 0;
00810         }
00811         if(ttm->tm_min == 0) {
00812                 while (isspace(*p))
00813                         p++;
00814                 if(*p != '0') {
00815                         free_sbuf(buf);
00816                         return 0;
00817                 }
00818         }
00819         get_substr(q, p);                       /*
00820                                                                  * seconds 
00821                                                                  */
00822         if(!p || (ttm->tm_sec = atoi(q)) > 59 || ttm->tm_sec < 0) {
00823                 free_sbuf(buf);
00824                 return 0;
00825         }
00826         if(ttm->tm_sec == 0) {
00827                 while (isspace(*q))
00828                         q++;
00829                 if(*q != '0') {
00830                         free_sbuf(buf);
00831                         return 0;
00832                 }
00833         }
00834         get_substr(p, q);                       /*
00835                                                                  * year 
00836                                                                  */
00837         if((ttm->tm_year = atoi(p)) == 0) {
00838                 while (isspace(*p))
00839                         p++;
00840                 if(*p != '0') {
00841                         free_sbuf(buf);
00842                         return 0;
00843                 }
00844         }
00845         free_sbuf(buf);
00846         if(ttm->tm_year > 100)
00847                 ttm->tm_year -= 1900;
00848         if(ttm->tm_year < 0) {
00849                 return 0;
00850         }
00851 #define LEAPYEAR_1900(yr) ((yr)%400==100||((yr)%100!=0&&(yr)%4==0))
00852         return (ttm->tm_mday != 29 || i != 1 || LEAPYEAR_1900(ttm->tm_year));
00853 #undef LEAPYEAR_1900
00854 }

static void do_edit_msg ( dbref  ,
char *  ,
char *   
) [static]

Definition at line 3016 of file mail.c.

References A_MAILMSG, atr_add(), atr_get(), Flags2, free_lbuf, notify, PLAYER_MAILS, and replace_string().

Referenced by do_mail().

03017 {
03018         char *result, *msg;
03019         dbref aowner;
03020         int aflags;
03021 
03022         if(Flags2(player) & PLAYER_MAILS) {
03023                 msg = atr_get(player, A_MAILMSG, &aowner, &aflags);
03024                 result = replace_string(from, to, msg);
03025                 atr_add(player, A_MAILMSG, result, aowner, aflags);
03026                 notify(player, "Text edited.");
03027                 free_lbuf(result);
03028                 free_lbuf(msg);
03029         } else {
03030                 notify(player, "MAIL: No message in progress.");
03031         }
03032 }

void do_expmail_abort ( dbref   ) 

Definition at line 2937 of file mail.c.

References Flags2, notify, and PLAYER_MAILS.

Referenced by do_mail().

02938 {
02939         Flags2(player) &= ~PLAYER_MAILS;
02940         notify(player, "MAIL: Message aborted.");
02941 }

void do_expmail_start ( dbref  player,
char *  arg,
char *  subject 
)

Definition at line 2633 of file mail.c.

References A_MAILFLAGS, A_MAILMSG, A_MAILSUB, A_MAILTO, atr_add_raw(), atr_clr(), Flags2, free_lbuf, make_namelist(), make_numlist(), names, notify, notify_printf(), and PLAYER_MAILS.

Referenced by do_mail_fwd(), and do_mail_stub().

02634 {
02635         char *tolist, *names;
02636 
02637         if(!arg || !*arg) {
02638                 notify(player, "MAIL: I do not know whom you want to mail.");
02639                 return;
02640         }
02641         if(!subject || !*subject) {
02642                 notify(player, "MAIL: No subject.");
02643                 return;
02644         }
02645         if(Flags2(player) & PLAYER_MAILS) {
02646                 notify(player, "MAIL: Mail message already in progress.");
02647                 return;
02648         }
02649         if(!(tolist = make_numlist(player, arg))) {
02650                 return;
02651         }
02652         atr_add_raw(player, A_MAILTO, tolist);
02653         atr_add_raw(player, A_MAILSUB, subject);
02654         atr_add_raw(player, A_MAILFLAGS, "0");
02655         atr_clr(player, A_MAILMSG);
02656         Flags2(player) |= PLAYER_MAILS;
02657         names = make_namelist(player, tolist);
02658         notify_printf(player, "MAIL: You are sending mail to '%s'.", names);
02659         free_lbuf(names);
02660         free_lbuf(tolist);
02661 }

void do_expmail_stop ( dbref  player,
int  flags 
)

Definition at line 2913 of file mail.c.

References A_MAILFLAGS, A_MAILMSG, A_MAILSUB, A_MAILTO, atr_get(), Flags2, free_lbuf, mail_to_list(), notify, and PLAYER_MAILS.

Referenced by do_mail(), and do_postpend().

02914 {
02915         char *tolist, *mailsub, *mailmsg, *mailflags;
02916         dbref aowner;
02917         dbref aflags;
02918 
02919         tolist = atr_get(player, A_MAILTO, &aowner, &aflags);
02920         mailmsg = atr_get(player, A_MAILMSG, &aowner, &aflags);
02921         mailsub = atr_get(player, A_MAILSUB, &aowner, &aflags);
02922         mailflags = atr_get(player, A_MAILFLAGS, &aowner, &aflags);
02923 
02924         if(!*tolist || !*mailmsg || !(Flags2(player) & PLAYER_MAILS)) {
02925                 notify(player, "MAIL: No such message to send.");
02926                 free_lbuf(tolist);
02927         } else {
02928                 mail_to_list(player, tolist, mailsub, mailmsg,
02929                                          flags | atoi(mailflags), 0);
02930         }
02931         free_lbuf(mailflags);
02932         free_lbuf(mailmsg);
02933         free_lbuf(mailsub);
02934         Flags2(player) &= ~PLAYER_MAILS;
02935 }

void do_mail ( dbref  player,
dbref  cause,
int  key,
char *  arg1,
char *  arg2 
)

Definition at line 1331 of file mail.c.

References do_edit_msg(), do_expmail_abort(), do_expmail_stop(), do_mail_cc(), do_mail_change_folder(), do_mail_clear(), do_mail_debug(), do_mail_file(), do_mail_fwd(), do_mail_list(), do_mail_nuke(), do_mail_proof(), do_mail_purge(), do_mail_quick(), do_mail_read(), do_mail_retract(), do_mail_review(), do_mail_safe(), do_mail_stats(), do_mail_stub(), do_mail_tag(), do_mail_unclear(), do_mail_untag(), do_malias_create(), do_malias_list_all(), confdata::have_mailer, M_URGENT, MAIL_ABORT, MAIL_ALIAS, MAIL_ALIST, MAIL_CC, MAIL_CLEAR, MAIL_DEBUG, MAIL_DSTATS, MAIL_EDIT, MAIL_FILE, MAIL_FOLDER, MAIL_FORWARD, MAIL_FSTATS, MAIL_LIST, MAIL_NUKE, MAIL_PROOF, MAIL_PURGE, MAIL_QUICK, MAIL_READ, MAIL_RETRACT, MAIL_REVIEW, MAIL_SAFE, MAIL_SEND, MAIL_STATS, MAIL_TAG, MAIL_UNCLEAR, MAIL_UNTAG, MAIL_URGENT, mudconf, and notify.

01332 {
01333         if(!mudconf.have_mailer) {
01334                 notify(player, "Mailer is disabled.");
01335                 return;
01336         }
01337         switch (key) {
01338         case 0:
01339                 do_mail_stub(player, arg1, arg2);
01340                 break;
01341         case MAIL_STATS:
01342                 do_mail_stats(player, arg1, 0);
01343                 break;
01344         case MAIL_DSTATS:
01345                 do_mail_stats(player, arg1, 1);
01346                 break;
01347         case MAIL_FSTATS:
01348                 do_mail_stats(player, arg1, 2);
01349                 break;
01350         case MAIL_DEBUG:
01351                 do_mail_debug(player, arg1, arg2);
01352                 break;
01353         case MAIL_NUKE:
01354                 do_mail_nuke(player);
01355                 break;
01356         case MAIL_FOLDER:
01357                 do_mail_change_folder(player, arg1, arg2);
01358                 break;
01359         case MAIL_LIST:
01360                 do_mail_list(player, arg1, 0);
01361                 break;
01362         case MAIL_READ:
01363                 do_mail_read(player, arg1);
01364                 break;
01365         case MAIL_CLEAR:
01366                 do_mail_clear(player, arg1);
01367                 break;
01368         case MAIL_UNCLEAR:
01369                 do_mail_unclear(player, arg1);
01370                 break;
01371         case MAIL_PURGE:
01372                 do_mail_purge(player);
01373                 break;
01374         case MAIL_FILE:
01375                 do_mail_file(player, arg1, arg2);
01376                 break;
01377         case MAIL_TAG:
01378                 do_mail_tag(player, arg1);
01379                 break;
01380         case MAIL_UNTAG:
01381                 do_mail_untag(player, arg1);
01382                 break;
01383         case MAIL_FORWARD:
01384                 do_mail_fwd(player, arg1, arg2);
01385                 break;
01386         case MAIL_SEND:
01387                 do_expmail_stop(player, 0);
01388                 break;
01389         case MAIL_EDIT:
01390                 do_edit_msg(player, arg1, arg2);
01391                 break;
01392         case MAIL_URGENT:
01393                 do_expmail_stop(player, M_URGENT);
01394                 break;
01395         case MAIL_ALIAS:
01396                 do_malias_create(player, arg1, arg2);
01397                 break;
01398         case MAIL_ALIST:
01399                 do_malias_list_all(player);
01400                 break;
01401         case MAIL_PROOF:
01402                 do_mail_proof(player);
01403                 break;
01404         case MAIL_ABORT:
01405                 do_expmail_abort(player);
01406                 break;
01407         case MAIL_QUICK:
01408                 do_mail_quick(player, arg1, arg2);
01409                 break;
01410         case MAIL_REVIEW:
01411                 do_mail_review(player, arg1, arg2);
01412                 break;
01413         case MAIL_RETRACT:
01414                 do_mail_retract(player, arg1, arg2);
01415                 break;
01416         case MAIL_CC:
01417                 do_mail_cc(player, arg1);
01418                 break;
01419         case MAIL_SAFE:
01420                 do_mail_safe(player, arg1);
01421                 break;
01422         }
01423 }

void do_mail_cc ( dbref  ,
char *   
)

Definition at line 2663 of file mail.c.

References A_MAILTO, alloc_lbuf, atr_add_raw(), atr_get_raw(), Flags2, free_lbuf, make_namelist(), make_numlist(), names, notify, notify_printf(), PLAYER_MAILS, safe_chr, and safe_str.

Referenced by do_mail().

02664 {
02665         char *tolist, *fulllist, *bp;
02666         char *names;
02667 
02668         if(!(Flags2(player) & PLAYER_MAILS)) {
02669                 notify(player, "MAIL: No mail message in progress.");
02670                 return;
02671         }
02672         if(!arg || !*arg) {
02673                 notify(player, "MAIL: I do not know whom you want to mail.");
02674                 return;
02675         }
02676         if(!(tolist = make_numlist(player, arg))) {
02677                 return;
02678         }
02679         fulllist = alloc_lbuf("do_mail_cc");
02680         bp = fulllist;
02681 
02682         safe_str(tolist, fulllist, &bp);
02683         if(atr_get_raw(player, A_MAILTO)) {
02684                 safe_chr(' ', fulllist, &bp);
02685                 safe_str(atr_get_raw(player, A_MAILTO), fulllist, &bp);
02686         }
02687         *bp = '\0';
02688 
02689         atr_add_raw(player, A_MAILTO, fulllist);
02690         names = make_namelist(player, fulllist);
02691         notify_printf(player, "MAIL: You are sending mail to '%s'.", names);
02692         free_lbuf(names);
02693         free_lbuf(tolist);
02694         free_lbuf(fulllist);
02695 }

void do_mail_change_folder ( dbref  player,
char *  fld,
char *  newname 
)

Definition at line 284 of file mail.c.

References add_folder_name(), check_mail(), FOLDER_NAME_LEN, get_folder_name(), MAX_FOLDERS, notify, notify_printf(), parse_folder(), player_folder(), and set_player_folder().

Referenced by do_mail().

00285 {
00286         int pfld;
00287         char *p;
00288 
00289         if(!fld || !*fld) {
00290                 /*
00291                  * Check mail in all folders 
00292                  */
00293                 for(pfld = MAX_FOLDERS; pfld >= 0; pfld--)
00294                         check_mail(player, pfld, 1);
00295 
00296                 pfld = player_folder(player);
00297                 notify_printf(player, "MAIL: Current folder is %d [%s].", pfld,
00298                                           get_folder_name(player, pfld));
00299 
00300                 return;
00301         }
00302         pfld = parse_folder(player, fld);
00303         if(pfld < 0) {
00304                 notify(player, "MAIL: What folder is that?");
00305                 return;
00306         }
00307         if(newname && *newname) {
00308                 /*
00309                  * We're changing a folder name here 
00310                  */
00311                 if(strlen(newname) > FOLDER_NAME_LEN) {
00312                         notify(player, "MAIL: Folder name too long");
00313                         return;
00314                 }
00315                 for(p = newname; p && *p; p++) {
00316                         if(!isalnum(*p)) {
00317                                 notify(player, "MAIL: Illegal folder name");
00318                                 return;
00319                         }
00320                 }
00321 
00322                 add_folder_name(player, pfld, newname);
00323                 notify_printf(player, "MAIL: Folder %d now named '%s'", pfld,
00324                                           newname);
00325         } else {
00326                 /*
00327                  * Set a new folder 
00328                  */
00329                 set_player_folder(player, pfld);
00330                 notify_printf(player, "MAIL: Current folder set to %d [%s].",
00331                                           pfld, get_folder_name(player, pfld));
00332         }
00333 }

void do_mail_clear ( dbref  player,
char *  msglist 
)

Definition at line 345 of file mail.c.

References do_mail_flags(), and M_CLEARED.

Referenced by destroy_player(), do_mail(), do_mail_debug(), and do_mail_stub().

00346 {
00347         do_mail_flags(player, msglist, M_CLEARED, 0);
00348 }

void do_mail_debug ( dbref  player,
char *  action,
char *  victim 
)

Definition at line 1022 of file mail.c.

References delete_mail_message(), do_mail_clear(), do_mail_purge(), Good_obj, init_match(), lookup_player(), statedata::mail_htab, MAIL_ITER_ALL, MAIL_ITER_SAFE, match_absolute(), match_result(), mudstate, Name(), mail::next, nhashrepl(), NOTHING, notify, notify_printf(), NOTYPE, string_prefix(), TYPE_PLAYER, Typeof, and Wizard.

Referenced by do_mail().

01023 {
01024         dbref target, thing;
01025         struct mail *mp, *nextp;
01026 
01027         if(!Wizard(player)) {
01028                 notify(player, "Go get some bugspray.");
01029                 return;
01030         }
01031         if(string_prefix("clear", action)) {
01032                 target = lookup_player(player, victim, 1);
01033                 if(target == NOTHING) {
01034                         init_match(player, victim, NOTYPE);
01035                         match_absolute();
01036                         target = match_result();
01037                 }
01038                 if(target == NOTHING) {
01039                         notify_printf(player, "%s: no such player.", victim);
01040                         return;
01041                 }
01042                 do_mail_clear(target, NULL);
01043                 do_mail_purge(target);
01044                 notify_printf(player, "Mail cleared for %s(#%d).", Name(target),
01045                                           target);
01046                 return;
01047         } else if(string_prefix("sanity", action)) {
01048                 MAIL_ITER_ALL(mp, thing) {
01049                         if(!Good_obj(mp->to))
01050                                 notify_printf(player, "Bad object #%d has mail.", mp->to);
01051                         else if(Typeof(mp->to) != TYPE_PLAYER)
01052                                 notify_printf(player,
01053                                                           "%s(#%d) has mail but is not a player.",
01054                                                           Name(mp->to), mp->to);
01055                 }
01056                 notify(player, "Mail sanity check completed.");
01057         } else if(string_prefix("fix", action)) {
01058                 MAIL_ITER_SAFE(mp, thing, nextp) {
01059                         if(!Good_obj(mp->to) || (Typeof(mp->to) != TYPE_PLAYER)) {
01060                                 notify_printf(player, "Fixing mail for #%d.", mp->to);
01061                                 /*
01062                                  * Delete this one 
01063                                  */
01064                                 /*
01065                                  * head and tail of the list are * special 
01066                                  */
01067                                 if(mp->prev == NULL)
01068                                         nhashrepl((int) player, (int *) mp->next,
01069                                                           &mudstate.mail_htab);
01070                                 else if(mp->next == NULL)
01071                                         mp->prev->next = NULL;
01072                                 /*
01073                                  * relink the list 
01074                                  */
01075                                 if(mp->prev != NULL)
01076                                         mp->prev->next = mp->next;
01077                                 if(mp->next != NULL)
01078                                         mp->next->prev = mp->prev;
01079                                 /*
01080                                  * save the pointer 
01081                                  */
01082                                 nextp = mp->next;
01083                                 /*
01084                                  * then wipe 
01085                                  */
01086                                 free((char *) mp->subject);
01087                                 delete_mail_message(mp->number);
01088                                 free((char *) mp->time);
01089                                 free((char *) mp->tolist);
01090                                 free(mp);
01091                         } else
01092                                 nextp = mp->next;
01093                 }
01094                 notify(player, "Mail sanity fix completed.");
01095         } else {
01096                 notify(player, "That is not a debugging option.");
01097                 return;
01098         }
01099 }

void do_mail_file ( dbref  player,
char *  msglist,
char *  folder 
)

Definition at line 423 of file mail.c.

References All, Folder, FolderBit, M_FMASK, statedata::mail_htab, mail_match(), mudstate, mail::next, nhashfind(), notify, notify_printf(), parse_folder(), parse_msglist(), player_folder(), and mail::read.

Referenced by do_mail().

00424 {
00425         struct mail *mp;
00426         struct mail_selector ms;
00427         int foldernum, origfold;
00428         int i = 0, j = 0;
00429 
00430         if(!parse_msglist(msglist, &ms, player)) {
00431                 return;
00432         }
00433         if((foldernum = parse_folder(player, folder)) == -1) {
00434                 notify(player, "MAIL: Invalid folder specification");
00435                 return;
00436         }
00437         origfold = player_folder(player);
00438         for(mp = (struct mail *) nhashfind((int) player, &mudstate.mail_htab);
00439                 mp; mp = mp->next) {
00440                 if(All(ms) || (Folder(mp) == origfold)) {
00441                         i++;
00442                         if(mail_match(mp, ms, i)) {
00443                                 j++;
00444                                 mp->read &= M_FMASK;    /*
00445                                                                                  * Clear the folder 
00446                                                                                  */
00447                                 mp->read |= FolderBit(foldernum);
00448                                 notify_printf(player, "MAIL: Msg %d filed in folder %d",
00449                                                           i, foldernum);
00450                         }
00451                 }
00452         }
00453 
00454         if(!j) {
00455                 /*
00456                  * ran off the end of the list without finding anything 
00457                  */
00458                 notify(player, "MAIL: You don't have any matching messages!");
00459         }
00460 }

static void do_mail_flags ( dbref  ,
char *  ,
mail_flag  ,
int   
) [static]

Definition at line 365 of file mail.c.

References All, Folder, M_CLEARED, M_SAFE, M_TAG, statedata::mail_htab, mail_match(), mudstate, mail::next, nhashfind(), notify, notify_printf(), parse_msglist(), player_folder(), mail::read, and Unread.

Referenced by do_mail_clear(), do_mail_safe(), do_mail_tag(), do_mail_unclear(), and do_mail_untag().

00367 {
00368         struct mail *mp;
00369         struct mail_selector ms;
00370         int i = 0, j = 0, folder;
00371 
00372         if(!parse_msglist(msglist, &ms, player)) {
00373                 return;
00374         }
00375         folder = player_folder(player);
00376         for(mp = (struct mail *) nhashfind((int) player, &mudstate.mail_htab);
00377                 mp; mp = mp->next) {
00378                 if(All(ms) || (Folder(mp) == folder)) {
00379                         i++;
00380                         if(mail_match(mp, ms, i)) {
00381                                 j++;
00382                                 if(negate) {
00383                                         mp->read &= ~flag;
00384                                 } else {
00385                                         mp->read |= flag;
00386                                 }
00387 
00388                                 switch (flag) {
00389                                 case M_TAG:
00390                                         notify_printf(player, "MAIL: Msg #%d %s.", i,
00391                                                                   negate ? "untagged" : "tagged");
00392                                         break;
00393                                 case M_CLEARED:
00394                                         if(Unread(mp) && !negate) {
00395                                                 notify_printf(player,
00396                                                                           "MAIL: Unread Msg #%d cleared! Use @mail/unclear %d to recover.",
00397                                                                           i, i);
00398                                         } else {
00399                                                 notify_printf(player, "MAIL: Msg #%d %s.", i,
00400                                                                           negate ? "uncleared" : "cleared");
00401                                         }
00402                                         break;
00403                                 case M_SAFE:
00404                                         notify_printf(player, "MAIL: Msg #%d marked safe.", i);
00405                                         break;
00406                                 }
00407                         }
00408                 }
00409         }
00410 
00411         if(!j) {
00412                 /*
00413                  * ran off the end of the list without finding anything 
00414                  */
00415                 notify(player, "MAIL: You don't have any matching messages!");
00416         }
00417 }

void do_mail_fwd ( dbref  player,
char *  msg,
char *  tolist 
)

Definition at line 819 of file mail.c.

References A_MAILFLAGS, A_MAILMSG, atr_add_raw(), atr_get_raw(), do_expmail_start(), mail::from, get_mail_message(), M_FORWARD, mail_fetch(), Name(), notify, mail::number, mail::subject, and tprintf().

Referenced by do_mail().

00820 {
00821         struct mail *mp;
00822         int num;
00823 
00824         if(!msg || !*msg) {
00825                 notify(player, "MAIL: No message list.");
00826                 return;
00827         }
00828         if(!tolist || !*tolist) {
00829                 notify(player, "MAIL: To whom should I forward?");
00830                 return;
00831         }
00832         num = atoi(msg);
00833         if(!num) {
00834                 notify(player, "MAIL: I don't understand that message number.");
00835                 return;
00836         }
00837         mp = mail_fetch(player, num);
00838         if(!mp) {
00839                 notify(player, "MAIL: You can't forward non-existent messages.");
00840                 return;
00841         }
00842         do_expmail_start(player, tolist, tprintf("%s (fwd from %s)",
00843                                                                                          mp->subject, Name(mp->from)));
00844         atr_add_raw(player, A_MAILMSG, get_mail_message(mp->number));
00845         atr_add_raw(player, A_MAILFLAGS, tprintf("%d",
00846                                                                                          (atoi
00847                                                                                           (atr_get_raw
00848                                                                                            (player,
00849                                                                                                 A_MAILFLAGS)) | M_FORWARD)));
00850 }

void do_mail_list ( dbref  player,
char *  msglist,
int  sub 
)

Definition at line 678 of file mail.c.

References Connected, DASH_LINE, Folder, free_lbuf, mail::from, get_mail_message(), Hasprivs, Hidden, statedata::mail_htab, mail_list_time(), mail_match(), mudstate, Name(), mail::next, nhashfind(), notify, notify_printf(), mail::number, parse_msglist(), player_folder(), PLAYER_NAME_LIMIT, status_chars(), mail::subject, mail::time, and time().

Referenced by do_mail(), and do_mail_stub().

00679 {
00680         struct mail *mp;
00681         struct mail_selector ms;
00682         int i = 0, folder;
00683         char *time;
00684 
00685         if(!parse_msglist(msglist, &ms, player)) {
00686                 return;
00687         }
00688         folder = player_folder(player);
00689 
00690         notify_printf(player,
00691                                   "---------------------------   MAIL: Folder %d   ----------------------------",
00692                                   folder);
00693 
00694         for(mp = (struct mail *) nhashfind((int) player, &mudstate.mail_htab);
00695                 mp; mp = mp->next) {
00696                 if(Folder(mp) == folder) {
00697                         i++;
00698                         if(mail_match(mp, ms, i)) {
00699                                 /*
00700                                  * list it 
00701                                  */
00702 
00703                                 time = mail_list_time(mp->time);
00704                                 if(sub)
00705                                         notify_printf(player,
00706                                                                   "[%s] %-3d (%4d) From: %-*s Sub: %.25s",
00707                                                                   status_chars(mp), i,
00708                                                                   strlen(get_mail_message(mp->number)),
00709                                                                   PLAYER_NAME_LIMIT - 6, Name(mp->from),
00710                                                                   mp->subject);
00711                                 else
00712                                         notify_printf(player,
00713                                                                   "[%s] %-3d (%4d) From: %-*s At: %s %s",
00714                                                                   status_chars(mp), i,
00715                                                                   strlen(get_mail_message(mp->number)),
00716                                                                   PLAYER_NAME_LIMIT - 6, Name(mp->from), time,
00717                                                                   ((Connected(mp->from)
00718                                                                         && (!Hidden(mp->from)
00719                                                                                 || Hasprivs(player))) ? "Conn" :
00720                                                                    " "));
00721                                 free_lbuf(time);
00722                         }
00723                 }
00724         }
00725         notify(player, DASH_LINE);
00726 }

void do_mail_nuke ( dbref  player  ) 

Definition at line 994 of file mail.c.

References delete_mail_message(), God, log_text(), MAIL_ITER_SAFE, Name(), mail::next, notify, mail::number, mail::subject, mail::time, mail::tolist, and tprintf().

Referenced by do_mail().

00995 {
00996         struct mail *mp, *nextp;
00997         dbref thing;
00998 
00999         if(!God(player)) {
01000                 notify(player,
01001                            "The postal service issues a warrant for your arrest.");
01002                 return;
01003         }
01004         /*
01005          * walk the list 
01006          */
01007         MAIL_ITER_SAFE(mp, thing, nextp) {
01008                 nextp = mp->next;
01009                 delete_mail_message(mp->number);
01010                 free((char *) mp->subject);
01011                 free((char *) mp->tolist);
01012                 free((char *) mp->time);
01013                 free(mp);
01014         }
01015 
01016         log_text(tprintf("** MAIL PURGE ** done by %s(#%d).", Name(player),
01017                                          (int) player));
01018 
01019         notify(player, "You annihilate the post office. All messages cleared.");
01020 }

static void do_mail_proof ( dbref   )  [static]

Definition at line 3034 of file mail.c.

References A_MAILMSG, A_MAILSUB, A_MAILTO, alloc_lbuf, atr_get(), atr_get_raw(), DASH_LINE, EV_EVAL, EV_FCHECK, exec(), Flags2, free_lbuf, make_namelist(), Name(), names, notify, notify_printf(), PLAYER_MAILS, and PLAYER_NAME_LIMIT.

Referenced by do_mail().

03035 {
03036         char *mailto, *names;
03037         char *mailmsg, *msg, *bp, *str;
03038         dbref aowner;
03039         int aflags;
03040 
03041         mailto = atr_get(player, A_MAILTO, &aowner, &aflags);
03042 
03043         if(!atr_get_raw(player, A_MAILMSG)) {
03044                 notify(player, "MAIL: No text.");
03045                 free_lbuf(mailto);
03046                 return;
03047         } else {
03048                 str = mailmsg = atr_get(player, A_MAILMSG, &aowner, &aflags);
03049                 bp = msg = alloc_lbuf("do_mail_proof");
03050                 exec(msg, &bp, 0, player, player, EV_EVAL | EV_FCHECK, &str,
03051                          (char **) NULL, 0);
03052                 *bp = '\0';
03053                 free_lbuf(mailmsg);
03054         }
03055 
03056         if(Flags2(player) & PLAYER_MAILS) {
03057                 names = make_namelist(player, mailto);
03058                 notify(player, DASH_LINE);
03059                 notify_printf(player, "From:  %-*s  Subject: %-35s\nTo: %s",
03060                                           PLAYER_NAME_LIMIT - 6, Name(player), atr_get_raw(player,
03061                                                                                                                                            A_MAILSUB),
03062                                           names);
03063                 notify(player, DASH_LINE);
03064                 notify(player, msg);
03065                 notify(player, DASH_LINE);
03066                 free_lbuf(names);
03067         } else {
03068                 notify(player, "MAIL: No message in progress.");
03069         }
03070         free_lbuf(mailto);
03071         free_lbuf(msg);
03072 }

void do_mail_purge ( dbref  player  ) 

Definition at line 765 of file mail.c.

References Cleared, delete_mail_message(), statedata::mail_htab, mudstate, mail::next, nhashdelete(), nhashfind(), nhashrepl(), and notify.

Referenced by announce_disconnect(), destroy_player(), do_mail(), do_mail_debug(), and do_mail_stub().

00766 {
00767         struct mail *mp, *nextp;
00768 
00769         /*
00770          * Go through player's mail, and remove anything marked cleared 
00771          */
00772         for(mp = (struct mail *) nhashfind((int) player, &mudstate.mail_htab);
00773                 mp; mp = nextp) {
00774                 if(Cleared(mp)) {
00775                         /*
00776                          * Delete this one 
00777                          */
00778                         /*
00779                          * head and tail of the list are special 
00780                          */
00781                         if(mp->prev == NULL)
00782                                 nhashrepl((int) player, (int *) mp->next,
00783                                                   &mudstate.mail_htab);
00784                         else if(mp->next == NULL)
00785                                 mp->prev->next = NULL;
00786 
00787                         /*
00788                          * relink the list 
00789                          */
00790                         if(mp->prev != NULL)
00791                                 mp->prev->next = mp->next;
00792                         if(mp->next != NULL)
00793                                 mp->next->prev = mp->prev;
00794 
00795                         /*
00796                          * save the pointer 
00797                          */
00798                         nextp = mp->next;
00799 
00800                         /* Clear it. its the last message in the list */
00801                         if(mp->prev == NULL && mp->next == NULL) 
00802                                 nhashdelete((int) player, &mudstate.mail_htab);
00803                                 
00804                         /*
00805                          * then wipe 
00806                          */
00807                         free((char *) mp->subject);
00808                         delete_mail_message(mp->number);
00809                         free((char *) mp->time);
00810                         free((char *) mp->tolist);
00811                         free(mp);
00812                 } else {
00813                         nextp = mp->next;
00814                 }
00815         }
00816         notify(player, "MAIL: Mailbox purged.");
00817 }

void do_mail_quick ( dbref  player,
char *  arg1,
char *  arg2 
)

Definition at line 2811 of file mail.c.

References alloc_lbuf, Flags2, free_lbuf, mail_to_list(), make_numlist(), notify, parse_to(), PLAYER_MAILS, and StringCopy.

Referenced by do_mail().

02812 {
02813         char *buf, *bp;
02814 
02815         if(!arg1 || !*arg1) {
02816                 notify(player, "MAIL: I don't know who you want to mail.");
02817                 return;
02818         }
02819         if(!arg2 || !*arg2) {
02820                 notify(player, "MAIL: No message.");
02821                 return;
02822         }
02823         if(Flags2(player) & PLAYER_MAILS) {
02824                 notify(player, "MAIL: Mail message already in progress.");
02825                 return;
02826         }
02827         buf = alloc_lbuf("do_mail_quick");
02828         bp = buf;
02829         StringCopy(bp, arg1);
02830 
02831         parse_to(&bp, '/', 1);
02832 
02833         if(!bp) {
02834                 notify(player, "MAIL: No subject.");
02835                 free_lbuf(buf);
02836                 return;
02837         }
02838         mail_to_list(player, make_numlist(player, buf), bp, arg2, 0, 0);
02839         free_lbuf(buf);
02840 }

void do_mail_read ( dbref  player,
char *  msglist 
)

Definition at line 466 of file mail.c.

References alloc_lbuf, Connected, DASH_LINE, Folder, free_lbuf, mail::from, get_mail_message(), Hasprivs, Hidden, M_ISREAD, statedata::mail_htab, mail_match(), make_namelist(), mudstate, Name(), names, mail::next, nhashfind(), notify, notify_printf(), mail::number, parse_msglist(), player_folder(), PLAYER_NAME_LIMIT, mail::read, status_string(), StringCopy, mail::subject, mail::time, mail::tolist, and Unread.

Referenced by do_mail(), and do_mail_stub().

00467 {
00468         struct mail *mp;
00469         char *tbuf1, *buff, *status, *names;
00470         struct mail_selector ms;
00471         int i = 0, j = 0, folder;
00472 
00473         tbuf1 = alloc_lbuf("do_mail_read");
00474 
00475         if(!parse_msglist(msglist, &ms, player)) {
00476                 free_lbuf(tbuf1);
00477                 return;
00478         }
00479         folder = player_folder(player);
00480         for(mp = (struct mail *) nhashfind((int) player, &mudstate.mail_htab);
00481                 mp; mp = mp->next) {
00482                 if(Folder(mp) == folder) {
00483                         i++;
00484                         if(mail_match(mp, ms, i)) {
00485                                 /*
00486                                  * Read it 
00487                                  */
00488                                 j++;
00489                                 buff = alloc_lbuf("do_mail_read");
00490                                 StringCopy(buff, get_mail_message(mp->number));
00491                                 notify(player, DASH_LINE);
00492                                 status = status_string(mp);
00493                                 names = make_namelist(player, (char *) mp->tolist);
00494                                 notify_printf(player,
00495                                                           "%-3d         From:  %-*s  At: %-25s  %s\r\nFldr   : %-2d Status: %s\r\nTo     : %-65s\r\nSubject: %-65s",
00496                                                           i, PLAYER_NAME_LIMIT - 6, Name(mp->from),
00497                                                           mp->time, (Connected(mp->from)
00498                                                                                  && (!Hidden(mp->from)
00499                                                                                          || Hasprivs(player))) ? " (Conn)"
00500                                                           : "      ", folder, status, names, mp->subject);
00501                                 free_lbuf(names);
00502                                 free_lbuf(status);
00503                                 notify(player, DASH_LINE);
00504                                 StringCopy(tbuf1, buff);
00505                                 notify(player, tbuf1);
00506                                 notify(player, DASH_LINE);
00507                                 free_lbuf(buff);
00508                                 if(Unread(mp))
00509                                         mp->read |= M_ISREAD;   /*
00510                                                                                          * mark * * * 
00511                                                                                          * message as 
00512                                                                                          * 
00513                                                                                          * *  * *  *
00514                                                                                          * * * read 
00515                                                                                          */
00516                         }
00517                 }
00518         }
00519 
00520         if(!j) {
00521                 /*
00522                  * ran off the end of the list without finding anything 
00523                  */
00524                 notify(player, "MAIL: You don't have that many matching messages!");
00525         }
00526         free_lbuf(tbuf1);
00527 }

void do_mail_retract ( dbref  player,
char *  name,
char *  msglist 
)

Definition at line 529 of file mail.c.

References delete_mail_message(), mail::from, lookup_player(), statedata::mail_htab, mail_match(), mudstate, mail::next, nhashfind(), nhashrepl(), NOTHING, notify, mail::number, parse_msglist(), mail::prev, mail::subject, mail::time, mail::tolist, and Unread.

Referenced by do_mail().

00530 {
00531         dbref target;
00532         struct mail *mp, *nextp;
00533         struct mail_selector ms;
00534         int i = 0, j = 0;
00535 
00536         target = lookup_player(player, name, 1);
00537         if(target == NOTHING) {
00538                 notify(player, "MAIL: No such player.");
00539                 return;
00540         }
00541         if(!parse_msglist(msglist, &ms, target)) {
00542                 return;
00543         }
00544         for(mp = (struct mail *) nhashfind((int) target, &mudstate.mail_htab);
00545                 mp; mp = nextp) {
00546                 if(mp->from == player) {
00547                         i++;
00548                         if(mail_match(mp, ms, i)) {
00549                                 j++;
00550                                 if(Unread(mp)) {
00551                                         if(mp->prev == NULL)
00552                                                 nhashrepl((int) target, (int *) mp->next,
00553                                                                   &mudstate.mail_htab);
00554                                         else if(mp->next == NULL)
00555                                                 mp->prev->next = NULL;
00556 
00557                                         if(mp->prev != NULL)
00558                                                 mp->prev->next = mp->next;
00559                                         if(mp->next != NULL)
00560                                                 mp->next->prev = mp->prev;
00561 
00562                                         nextp = mp->next;
00563                                         free((char *) mp->subject);
00564                                         delete_mail_message(mp->number);
00565                                         free((char *) mp->time);
00566                                         free((char *) mp->tolist);
00567                                         free(mp);
00568                                         notify(player, "MAIL: Mail retracted.");
00569                                 } else {
00570                                         notify(player, "MAIL: That message has been read.");
00571                                         nextp = mp->next;
00572                                 }
00573                         } else {
00574                                 nextp = mp->next;
00575                         }
00576                 } else {
00577                         nextp = mp->next;
00578                 }
00579         }
00580 
00581         if(!j) {
00582                 /*
00583                  * ran off the end of the list without finding anything 
00584                  */
00585                 notify(player, "MAIL: No matching messages.");
00586         }
00587 }

void do_mail_review ( dbref  player,
char *  name,
char *  msglist 
)

Definition at line 589 of file mail.c.

References alloc_lbuf, Connected, DASH_LINE, EV_EVAL, EV_FCHECK, EV_NO_COMPRESS, exec(), free_lbuf, mail::from, get_mail_message(), Hasprivs, Hidden, lookup_player(), statedata::mail_htab, mail_match(), msgbuff, mudstate, Name(), mail::next, nhashfind(), NOTHING, notify, notify_printf(), mail::number, parse_msglist(), PLAYER_NAME_LIMIT, status_chars(), status_string(), StringCopy, mail::subject, and mail::time.

Referenced by do_mail().

00590 {
00591         struct mail *mp;
00592         struct mail_selector ms;
00593         int i = 0, j = 0;
00594         dbref target;
00595         char *tbuf1, *msg, *status, *bp, *str;
00596 
00597         target = lookup_player(player, name, 1);
00598         if(target == NOTHING) {
00599                 notify(player, "MAIL: No such player.");
00600                 return;
00601         }
00602         if(!msglist || !*msglist) {
00603                 notify_printf(player,
00604                                           "--------------------   MAIL: %-25s   ------------------",
00605                                           Name(target));
00606                 for(mp =
00607                         (struct mail *) nhashfind((int) target, &mudstate.mail_htab);
00608                         mp; mp = mp->next) {
00609                         if(mp->from == player) {
00610                                 i++;
00611                                 /*
00612                                  * list it 
00613                                  */
00614                                 notify_printf(player,
00615                                                           "[%s] %-3d (%4d) From: %-*s Sub: %.25s",
00616                                                           status_chars(mp), i,
00617                                                           strlen(get_mail_message(mp->number)),
00618                                                           PLAYER_NAME_LIMIT - 6, Name(mp->from),
00619                                                           mp->subject);
00620                         }
00621                 }
00622                 notify(player, DASH_LINE);
00623         } else {
00624                 tbuf1 = alloc_lbuf("do_mail_read");
00625 
00626                 if(!parse_msglist(msglist, &ms, target)) {
00627                         free_lbuf(tbuf1);
00628                         return;
00629                 }
00630                 for(mp =
00631                         (struct mail *) nhashfind((int) target, &mudstate.mail_htab);
00632                         mp; mp = mp->next) {
00633                         if(mp->from == player) {
00634                                 i++;
00635                                 if(mail_match(mp, ms, i)) {
00636                                         /*
00637                                          * Read it 
00638                                          */
00639                                         j++;
00640                                         status = status_string(mp);
00641                                         strcpy(msgbuff, get_mail_message(mp->number));
00642                                         msg = bp = alloc_lbuf("do_mail_review");
00643                                         str = msgbuff;
00644                                         exec(msg, &bp, 0, player, player,
00645                                                  EV_EVAL | EV_FCHECK | EV_NO_COMPRESS, &str,
00646                                                  (char **) NULL, 0);
00647                                         *bp = '\0';
00648                                         notify(player, DASH_LINE);
00649                                         notify_printf(player,
00650                                                                   "%-3d         From:  %-*s  At: %-25s  %s\r\nFldr   : %-2d Status: %s\r\nSubject: %-65s",
00651                                                                   i, PLAYER_NAME_LIMIT - 6, Name(mp->from),
00652                                                                   mp->time, (Connected(mp->from) &&
00653                                                                                          (!Hidden(mp->from) ||
00654                                                                                           Hasprivs(player))) ? " (Conn)" :
00655                                                                   "      ", 0, status, mp->subject);
00656                                         free_lbuf(status);
00657                                         notify(player, DASH_LINE);
00658                                         StringCopy(tbuf1, msg);
00659                                         notify(player, tbuf1);
00660                                         notify(player, DASH_LINE);
00661                                         free_lbuf(msg);
00662                                 }
00663                         }
00664                 }
00665 
00666                 if(!j) {
00667                         /*
00668                          * ran off the end of the list without finding * * *
00669                          * anything 
00670                          */
00671                         notify(player,
00672                                    "MAIL: You don't have that many matching messages!");
00673                 }
00674                 free_lbuf(tbuf1);
00675         }
00676 }

void do_mail_safe ( dbref  player,
char *  msglist 
)

Definition at line 340 of file mail.c.

References do_mail_flags(), and M_SAFE.

Referenced by do_mail().

00341 {
00342         do_mail_flags(player, msglist, M_SAFE, 0);
00343 }

void do_mail_stats ( dbref  player,
char *  name,
int  full 
)

Definition at line 1101 of file mail.c.

References AMBIGUOUS, Cleared, mail::from, get_mail_message(), Good_obj, init_match(), lookup_player(), MAIL_ITER_ALL, confdata::many_coins, match_absolute(), match_result(), mudconf, Name(), NOTHING, notify, notify_printf(), NOTYPE, mail::number, NUMBER_TOKEN, confdata::one_coin, payfor(), Read, confdata::searchcost, StringCopy, mail::time, mail::to, TYPE_PLAYER, Typeof, and Wizard.

Referenced by do_mail().

01102 {
01103         dbref target, thing;
01104         int fc, fr, fu, tc, tr, tu, fchars, tchars, cchars, count;
01105         char last[50];
01106         struct mail *mp;
01107 
01108         fc = fr = fu = tc = tr = tu = cchars = fchars = tchars = count = 0;
01109 
01110         /*
01111          * find player 
01112          */
01113 
01114         if((*name == '\0') || !name) {
01115                 if(Wizard(player))
01116                                 target = AMBIGUOUS;
01117                 else
01118                         target = player;
01119         } else if(*name == NUMBER_TOKEN) {
01120                 target = atoi(&name[1]);
01121                 if(!Good_obj(target) || (Typeof(target) != TYPE_PLAYER))
01122                         target = NOTHING;
01123         } else if(!strcasecmp(name, "me")) {
01124                 target = player;
01125         } else {
01126                 target = lookup_player(player, name, 1);
01127         }
01128 
01129         if(target == NOTHING) {
01130                 init_match(player, name, NOTYPE);
01131                 match_absolute();
01132                 target = match_result();
01133         }
01134         if(target == NOTHING) {
01135                 notify_printf(player, "%s: No such player.", name);
01136                 return;
01137         }
01138         if(!Wizard(player) && (target != player)) {
01139                 notify(player, "The post office protects privacy!");
01140                 return;
01141         }
01142         /*
01143          * this comand is computationally expensive 
01144          */
01145 
01146         if(!payfor(player, mudconf.searchcost)) {
01147                 notify_printf(player, "Finding mail stats costs %d %s.",
01148                                           mudconf.searchcost,
01149                                           (mudconf.searchcost ==
01150                                            1) ? mudconf.one_coin : mudconf.many_coins);
01151                 return;
01152         }
01153         if(target == AMBIGUOUS) {       /*
01154                                                                  * stats for all 
01155                                                                  */
01156                 if(full == 0) {
01157                         MAIL_ITER_ALL(mp, thing) {
01158                                 count++;
01159                         }
01160                         notify_printf(player,
01161                                                   "There are %d messages in the mail spool.", count);
01162                         return;
01163                 } else if(full == 1) {
01164                         MAIL_ITER_ALL(mp, thing) {
01165                                 if(Cleared(mp))
01166                                         fc++;
01167                                 else if(Read(mp))
01168                                         fr++;
01169                                 else
01170                                         fu++;
01171                         }
01172                         notify_printf(player,
01173                                                   "MAIL: There are %d msgs in the mail spool, %d unread, %d cleared.",
01174                                                   fc + fr + fu, fu, fc);
01175                         return;
01176                 } else {
01177                         MAIL_ITER_ALL(mp, thing) {
01178 
01179                                 if(Cleared(mp)) {
01180                                         fc++;
01181                                         cchars += strlen(get_mail_message(mp->number));
01182                                 } else if(Read(mp)) {
01183                                         fr++;
01184                                         fchars += strlen(get_mail_message(mp->number));
01185                                 } else {
01186                                         fu++;
01187                                         tchars += strlen(get_mail_message(mp->number));
01188                                 }
01189                         }
01190                         notify_printf(player,
01191                                                   "MAIL: There are %d old msgs in the mail spool, totalling %d characters.",
01192                                                   fr, fchars);
01193                         notify_printf(player,
01194                                                   "MAIL: There are %d new msgs in the mail spool, totalling %d characters.",
01195                                                   fu, tchars);
01196                         notify_printf(player,
01197                                                   "MAIL: There are %d cleared msgs in the mail spool, totalling %d characters.",
01198                                                   fc, cchars);
01199                         return;
01200                 }
01201         }
01202         /*
01203          * individual stats 
01204          */
01205 
01206         if(full == 0) {
01207                 /*
01208                  * just count number of messages 
01209                  */
01210                 MAIL_ITER_ALL(mp, thing) {
01211                         if(mp->from == target)
01212                                 fr++;
01213                         if(mp->to == target)
01214                                 tr++;
01215                 }
01216                 notify_printf(player, "%s sent %d messages.", Name(target), fr);
01217                 notify_printf(player, "%s has %d messages.", Name(target), tr);
01218                 return;
01219         }
01220         /*
01221          * more detailed message count 
01222          */
01223         MAIL_ITER_ALL(mp, thing) {
01224                 if(mp->from == target) {
01225                         if(Cleared(mp))
01226                                 fc++;
01227                         else if(Read(mp))
01228                                 fr++;
01229                         else
01230                                 fu++;
01231                         if(full == 2)
01232                                 fchars += strlen(get_mail_message(mp->number));
01233                 }
01234                 if(mp->to == target) {
01235                         if(!tr && !tu) {
01236                                 StringCopy(last, mp->time);
01237                         }
01238                         if(Cleared(mp))
01239                                 tc++;
01240                         else if(Read(mp))
01241                                 tr++;
01242                         else
01243                                 tu++;
01244                         if(full == 2) {
01245                                 tchars += strlen(get_mail_message(mp->number));
01246                         }
01247                 }
01248         }
01249 
01250         notify_printf(player, "Mail statistics for %s:", Name(target));
01251 
01252         if(full == 1) {
01253                 notify_printf(player, "%d messages sent, %d unread, %d cleared.",
01254                                           fc + fr + fu, fu, fc);
01255                 notify_printf(player,
01256                                           "%d messages received, %d unread, %d cleared.",
01257                                           tc + tr + tu, tu, tc);
01258         } else {
01259                 notify_printf(player,
01260                                           "%d messages sent, %d unread, %d cleared, totalling %d characters.",
01261                                           fc + fr + fu, fu, fc, fchars);
01262                 notify_printf(player,
01263                                           "%d messages received, %d unread, %d cleared, totalling %d characters.",
01264                                           tc + tr + tu, tu, tc, tchars);
01265         }
01266 
01267         if(tc + tr + tu > 0)
01268                 notify_printf(player, "Last is dated %s", last);
01269         return;
01270 }

void do_mail_stub ( dbref  player,
char *  arg1,
char *  arg2 
)

Definition at line 1276 of file mail.c.

References do_expmail_start(), do_mail_clear(), do_mail_list(), do_mail_purge(), do_mail_read(), do_mail_unclear(), notify, TYPE_PLAYER, and Typeof.

Referenced by do_mail().

01277 {
01278 
01279         if(Typeof(player) != TYPE_PLAYER) {
01280                 notify(player, "MAIL: Only players may send and receive mail.");
01281                 return;
01282         }
01283         if(!arg1 || !*arg1) {
01284                 if(arg2 && *arg2) {
01285                         notify(player, "MAIL: Invalid mail command.");
01286                         return;
01287                 }
01288                 /*
01289                  * just the "@mail" command 
01290                  */
01291                 do_mail_list(player, arg1, 1);
01292                 return;
01293         }
01294         /*
01295          * purge a player's mailbox 
01296          */
01297         if(!strcasecmp(arg1, "purge")) {
01298                 do_mail_purge(player);
01299                 return;
01300         }
01301         /*
01302          * clear message 
01303          */
01304         if(!strcasecmp(arg1, "clear")) {
01305                 do_mail_clear(player, arg2);
01306                 return;
01307         }
01308         if(!strcasecmp(arg1, "unclear")) {
01309                 do_mail_unclear(player, arg2);
01310                 return;
01311         }
01312         if(arg2 && *arg2) {
01313                 /*
01314                  * Sending mail 
01315                  */
01316                 do_expmail_start(player, arg1, arg2);
01317                 return;
01318         } else {
01319                 /*
01320                  * Must be reading or listing mail - no arg2 
01321                  */
01322                 if(isdigit(*arg1) && !index(arg1, '-'))
01323                         do_mail_read(player, arg1);
01324                 else
01325                         do_mail_list(player, arg1, 1);
01326                 return;
01327         }
01328 
01329 }

void do_mail_tag ( dbref  player,
char *  msglist 
)

Definition at line 335 of file mail.c.

References do_mail_flags(), and M_TAG.

Referenced by do_mail().

00336 {
00337         do_mail_flags(player, msglist, M_TAG, 0);
00338 }

void do_mail_unclear ( dbref  player,
char *  msglist 
)

Definition at line 355 of file mail.c.

References do_mail_flags(), and M_CLEARED.

Referenced by do_mail(), and do_mail_stub().

00356 {
00357         do_mail_flags(player, msglist, M_CLEARED, 1);
00358 }

void do_mail_untag ( dbref  player,
char *  msglist 
)

Definition at line 350 of file mail.c.

References do_mail_flags(), and M_TAG.

Referenced by do_mail().

00351 {
00352         do_mail_flags(player, msglist, M_TAG, 1);
00353 }

void do_malias ( dbref  player,
dbref  cause,
int  key,
char *  arg1,
char *  arg2 
)

Definition at line 2274 of file mail.c.

References do_malias_add(), do_malias_adminlist(), do_malias_chown(), do_malias_delete(), do_malias_desc(), do_malias_remove(), do_malias_rename(), do_malias_status(), do_malias_switch(), confdata::have_mailer, mudconf, and notify.

02275 {
02276         if(!mudconf.have_mailer) {
02277                 notify(player, "Mailer is disabled.");
02278                 return;
02279         }
02280         switch (key) {
02281         case 0:
02282                 do_malias_switch(player, arg1, arg2);
02283                 break;
02284         case 1:
02285                 do_malias_desc(player, arg1, arg2);
02286                 break;
02287         case 2:
02288                 do_malias_chown(player, arg1, arg2);
02289                 break;
02290         case 3:
02291                 do_malias_add(player, arg1, arg2);
02292                 break;
02293         case 4:
02294                 do_malias_remove(player, arg1, arg2);
02295                 break;
02296         case 5:
02297                 do_malias_delete(player, arg1);
02298                 break;
02299         case 6:
02300                 do_malias_rename(player, arg1, arg2);
02301                 break;
02302         case 7:
02303                 /*
02304                  * empty 
02305                  */
02306                 break;
02307         case 8:
02308                 do_malias_adminlist(player);
02309                 break;
02310         case 9:
02311                 do_malias_status(player);
02312         }
02313 }

void do_malias_add ( dbref  player,
char *  alias,
char *  person 
)

Definition at line 3117 of file mail.c.

References ExpMail, get_malias(), GOD, isPlayer, malias::list, lookup_player(), malias, NOTHING, notify, notify_printf(), malias::numrecep, malias::owner, and parse_dbref().

Referenced by do_malias().

03118 {
03119         int i = 0;
03120         dbref thing;
03121         struct malias *m;
03122 
03123         thing = NOTHING;
03124 
03125         if(!(m = get_malias(player, alias))) {
03126                 notify_printf(player, "MAIL: Alias %s not found.", alias);
03127                 return;
03128         }
03129         if(*person == '#') {
03130                 thing = parse_dbref(person + 1);
03131                 if(!isPlayer(thing)) {
03132                         notify(player, "MAIL: Only players may be added.");
03133                         return;
03134                 }
03135         }
03136 
03137         if(thing == NOTHING)
03138                 thing = lookup_player(player, person, 1);
03139 
03140         if(thing == NOTHING) {
03141                 notify(player, "MAIL: I do not see that person here.");
03142                 return;
03143         }
03144 
03145         if((m->owner == GOD) && !ExpMail(player)) {
03146                 notify(player, "MAIL: Permission denied.");
03147                 return;
03148         }
03149         for(i = 0; i < m->numrecep; i++) {
03150                 if(m->list[i] == thing) {
03151                         notify(player, "MAIL: That person is already on the list.");
03152                         return;
03153                 }
03154         }
03155 
03156         if(i >= (MALIAS_LEN - 1)) {
03157                 notify(player, "MAIL: The list is full.");
03158                 return;
03159         }
03160 
03161         m->list[m->numrecep] = thing;
03162         m->numrecep = m->numrecep + 1;
03163         notify_printf(player, "MAIL: %s added to %s", Name(thing), m->name);
03164 }

void do_malias_adminlist ( dbref  player  ) 

Definition at line 3271 of file mail.c.

References malias::desc, do_malias_list_all(), ExpMail, ma_top, malias, malias::name, Name(), notify, notify_printf(), and malias::owner.

Referenced by do_malias().

03272 {
03273         struct malias *m;
03274         int i;
03275 
03276         if(!ExpMail(player)) {
03277                 do_malias_list_all(player);
03278                 return;
03279         }
03280         notify(player,
03281                    "Num  Name       Description                              Owner");
03282 
03283         for(i = 0; i < ma_top; i++) {
03284                 m = malias[i];
03285                 notify_printf(player, "%-4d %-10.10s %-40.40s %-11.11s", i,
03286                                           m->name, m->desc, Name(m->owner));
03287         }
03288 
03289         notify(player, "***** End of Mail Aliases *****");
03290 }

void do_malias_chown ( dbref  player,
char *  alias,
char *  owner 
)

Definition at line 3094 of file mail.c.

References ExpMail, get_malias(), lookup_player(), malias, NOTHING, notify, notify_printf(), and malias::owner.

Referenced by do_malias().

03095 {
03096         struct malias *m;
03097         dbref no = NOTHING;
03098 
03099         if(!(m = get_malias(player, alias))) {
03100                 notify_printf(player, "MAIL: Alias %s not found.", alias);
03101                 return;
03102         } else {
03103                 if(!ExpMail(player)) {
03104                         notify(player, "MAIL: You cannot do that!");
03105                         return;
03106                 } else {
03107                         if((no = lookup_player(player, owner, 1)) == NOTHING) {
03108                                 notify(player, "MAIL: I do not see that here.");
03109                                 return;
03110                         }
03111                         m->owner = no;
03112                         notify(player, "MAIL: Owner changed for alias.");
03113                 }
03114         }
03115 }

void do_malias_create ( dbref  player,
char *  alias,
char *  tolist 
)

Definition at line 2386 of file mail.c.

References desc, free_lbuf, get_malias(), Good_obj, lookup_player(), MA_INC, ma_size, ma_top, malias, MALIAS_LEN, name, NOTHING, notify, notify_printf(), StringCopy, TYPE_PLAYER, Typeof, and unparse_object().

Referenced by do_mail(), and do_malias_switch().

02387 {
02388         char *head, *tail, spot;
02389         struct malias *m;
02390         struct malias **nm;
02391         char *na, *buff;
02392         int i = 0;
02393         dbref target;
02394 
02395         if(Typeof(player) != TYPE_PLAYER) {
02396                 notify(player, "MAIL: Only players may create mail aliases.");
02397                 return;
02398         }
02399         if(!alias || !*alias || !tolist || !*tolist) {
02400                 notify(player, "MAIL: What alias do you want to create?.");
02401                 return;
02402         }
02403         if(*alias != '*') {
02404                 notify(player, "MAIL: All Mail aliases must begin with '*'.");
02405                 return;
02406         }
02407         m = get_malias(player, alias);
02408         if(m) {
02409                 notify_printf(player, "MAIL: Mail Alias '%s' already exists.", alias);
02410                 return;
02411         }
02412         if(!ma_size) {
02413                 ma_size = MA_INC;
02414                 malias = (struct malias **) malloc(sizeof(struct malias *) * ma_size);
02415         } else if(ma_top >= ma_size) {
02416                 ma_size += MA_INC;
02417                 nm = (struct malias **) malloc(sizeof(struct malias *) * (ma_size));
02418 
02419                 for(i = 0; i < ma_top; i++)
02420                         nm[i] = malias[i];
02421                 free(malias);
02422                 malias = nm;
02423         }
02424         malias[ma_top] = (struct malias *) malloc(sizeof(struct malias));
02425 
02426         i = 0;
02427 
02428         /*
02429          * Parse the player list 
02430          */
02431         head = (char *) tolist;
02432         while (head && *head && (i < (MALIAS_LEN - 1))) {
02433                 while (*head == ' ')
02434                         head++;
02435                 tail = head;
02436                 while (*tail && (*tail != ' ')) {
02437                         if(*tail == '"') {
02438                                 head++;
02439                                 tail++;
02440                                 while (*tail && (*tail != '"'))
02441                                         tail++;
02442                         }
02443                         if(*tail)
02444                                 tail++;
02445                 }
02446                 tail--;
02447                 if(*tail != '"')
02448                         tail++;
02449                 spot = *tail;
02450                 *tail = '\0';
02451                 /*
02452                  * Now locate a target 
02453                  */
02454                 if(!strcasecmp(head, "me"))
02455                         target = player;
02456                 else if(*head == '#') {
02457                         target = atoi(head + 1);
02458                         if(!Good_obj(target))
02459                                 target = NOTHING;
02460                 } else
02461                         target = lookup_player(player, head, 1);
02462                 if((target == NOTHING) || (Typeof(target) != TYPE_PLAYER)) {
02463                         notify(player, "MAIL: No such player.");
02464                 } else {
02465                         buff = unparse_object(player, target, 0);
02466                         notify_printf(player, "MAIL: %s added to alias %s", buff, alias);
02467                         malias[ma_top]->list[i] = target;
02468                         i++;
02469                         free_lbuf(buff);
02470                 }
02471                 /*
02472                  * Get the next recip 
02473                  */
02474                 *tail = spot;
02475                 head = tail;
02476                 if(*head == '"')
02477                         head++;
02478         }
02479         malias[ma_top]->list[i] = NOTHING;
02480 
02481         na = alias + 1;
02482         malias[ma_top]->name = (char *) malloc(strlen(na) + 1);
02483         malias[ma_top]->numrecep = i;
02484         malias[ma_top]->owner = player;
02485         StringCopy(malias[ma_top]->name, na);
02486         malias[ma_top]->desc = (char *) malloc(strlen(na) + 1);
02487         StringCopy(malias[ma_top]->desc, na);   /*
02488                                                                                          * For now do this. 
02489                                                                                          */
02490         ma_top++;
02491 
02492         notify_printf(player, "MAIL: Alias set '%s' defined.", alias);
02493 }

void do_malias_delete ( dbref  player,
char *  alias 
)

Definition at line 3238 of file mail.c.

References ExpMail, get_malias(), ma_top, malias, notify, and malias::owner.

Referenced by do_malias().

03239 {
03240         int i = 0;
03241         int done = 0;
03242         struct malias *m;
03243 
03244         m = get_malias(player, alias);
03245 
03246         if(!m) {
03247                 notify(player,
03248                            "MAIL: Not a valid alias. Remember to prefix the alias name with *.");
03249                 return;
03250         }
03251 
03252         for(i = 0; i < ma_top; i++) {
03253                 if(done)
03254                         malias[i] = malias[i + 1];
03255                 else {
03256                         if((m->owner == player) || ExpMail(player))
03257                                 if(m == malias[i]) {
03258                                         done = 1;
03259                                         notify(player, "MAIL: Alias Deleted.");
03260                                         malias[i] = malias[i + 1];
03261                                 }
03262                 }
03263         }
03264 
03265         if(!done)
03266                 notify(player, "MAIL: Alias not found.");
03267         else
03268                 ma_top--;
03269 }

void do_malias_desc ( dbref  player,
char *  alias,
char *  desc 
)

Definition at line 3074 of file mail.c.

References malias::desc, ExpMail, get_malias(), GOD, malias, notify, notify_printf(), malias::owner, and StringCopy.

Referenced by do_malias().

03075 {
03076         struct malias *m;
03077 
03078         if(!(m = get_malias(player, alias))) {
03079                 notify_printf(player, "MAIL: Alias %s not found.", alias);
03080                 return;
03081         } else if((m->owner != GOD) || ExpMail(player)) {
03082                 free(m->desc);                  /*
03083                                                                  * free it up 
03084                                                                  */
03085                 m->desc = (char *) malloc(sizeof(char *) * strlen(desc));
03086 
03087                 StringCopy(m->desc, desc);
03088                 notify(player, "MAIL: Description changed.");
03089         } else
03090                 notify(player, "MAIL: Permission denied.");
03091         return;
03092 }

void do_malias_list ( dbref  player,
char *  alias 
)

Definition at line 2495 of file mail.c.

References alloc_lbuf, ExpMail, free_lbuf, get_malias(), God, malias::list, malias, malias::name, Name(), notify, notify_printf(), malias::numrecep, malias::owner, safe_chr, safe_str, and safe_tprintf_str().

Referenced by do_malias_switch().

02496 {
02497         struct malias *m;
02498         int i = 0;
02499         char *buff, *bp;
02500 
02501         m = get_malias(player, alias);
02502 
02503         if(!m) {
02504                 notify_printf(player, "MAIL: Alias '%s' not found.", alias);
02505                 return;
02506         }
02507         if(!ExpMail(player) && (player != m->owner) && !(God(m->owner))) {
02508                 notify(player, "MAIL: Permission denied.");
02509                 return;
02510         }
02511         bp = buff = alloc_lbuf("do_malias_list");
02512         safe_tprintf_str(buff, &bp, "MAIL: Alias *%s: ", m->name);
02513         for(i = m->numrecep - 1; i > -1; i--) {
02514                 safe_str(Name(m->list[i]), buff, &bp);
02515                 safe_chr(' ', buff, &bp);
02516         }
02517         *bp = '\0';
02518 
02519         notify(player, buff);
02520         free_lbuf(buff);
02521 }

void do_malias_list_all ( dbref  player  ) 

Definition at line 2523 of file mail.c.

References malias::desc, GOD, God, ma_top, malias, malias::name, Name(), notify, notify_printf(), and malias::owner.

Referenced by do_mail(), do_malias_adminlist(), and do_malias_switch().

02524 {
02525         struct malias *m;
02526         int i = 0;
02527         int notified = 0;
02528 
02529         for(i = 0; i < ma_top; i++) {
02530                 m = malias[i];
02531                 if((m->owner == GOD) || (m->owner == player) || God(player)) {
02532                         if(!notified) {
02533                                 notify(player,
02534                                            "Name         Description                         Owner");
02535                                 notified++;
02536                         }
02537                         notify_printf(player, "%-12.12s %-35.35s %-15.15s", m->name,
02538                                                   m->desc, Name(m->owner));
02539                 }
02540         }
02541 
02542         notify(player, "*****  End of Mail Aliases *****");
02543 }

void do_malias_remove ( dbref  player,
char *  alias,
char *  person 
)

Definition at line 3166 of file mail.c.

References ExpMail, get_malias(), GOD, malias::list, lookup_player(), malias, NOTHING, notify, malias::numrecep, malias::owner, and parse_dbref().

Referenced by do_malias().

03167 {
03168         int i, ok = 0;
03169         dbref thing;
03170         struct malias *m;
03171 
03172         thing = NOTHING;
03173 
03174         if(!(m = get_malias(player, alias))) {
03175                 notify(player, "MAIL: Alias not found.");
03176                 return;
03177         }
03178         if((m->owner == GOD) && !ExpMail(player)) {
03179                 notify(player, "MAIL: Permission denied.");
03180                 return;
03181         }
03182 
03183         if(*person == '#')
03184                 thing = parse_dbref(person + 1);
03185 
03186         if(thing == NOTHING)
03187                 thing = lookup_player(player, person, 1);
03188 
03189         if(thing == NOTHING) {
03190                 notify(player, "MAIL: I do not see that person here.");
03191                 return;
03192         }
03193 
03194         for(i = 0; i < m->numrecep; i++) {
03195                 if(ok)
03196                         m->list[i] = m->list[i + 1];
03197                 else if((m->list[i] == thing) && !ok) {
03198                         m->list[i] = m->list[i + 1];
03199                         ok = 1;
03200                 }
03201         }
03202 
03203         if(ok)
03204                 m->numrecep--;
03205 
03206         notify_printf(player, "MAIL: %s removed from alias %s.", Name(thing),
03207                                   alias);
03208 }

void do_malias_rename ( dbref  player,
char *  alias,
char *  newname 
)

Definition at line 3210 of file mail.c.

References ExpMail, get_malias(), malias, malias::name, notify, malias::owner, and StringCopy.

Referenced by do_malias().

03211 {
03212         struct malias *m;
03213 
03214         if(get_malias(player, newname) != NULL) {
03215                 notify(player, "MAIL: That name already exists!");
03216                 return;
03217         }
03218         if((m = get_malias(player, alias)) == NULL) {
03219                 notify(player, "MAIL: I cannot find that alias!");
03220                 return;
03221         }
03222         if(*newname != '*') {
03223                 notify(player, "MAIL: Bad alias.");
03224                 return;
03225         }
03226         if(!ExpMail(player) && !(m->owner == player)) {
03227                 notify(player, "MAIL: Permission denied.");
03228                 return;
03229         }
03230         free(m->name);
03231         m->name = (char *) malloc(sizeof(char) * strlen(newname));
03232 
03233         StringCopy(m->name, newname + 1);
03234 
03235         notify(player, "MAIL: Mailing Alias renamed.");
03236 }

void do_malias_send ( dbref  player,
char *  tolist,
char *  listto,
char *  subject,
int  number,
mail_flag  flags,
int  silent 
)

Definition at line 2315 of file mail.c.

References add_mail_message(), get_malias(), GOD, malias::list, malias, notify, notify_printf(), malias::numrecep, send_mail(), tprintf(), TYPE_PLAYER, and Typeof.

Referenced by mail_to_list().

02317 {
02318         int k;
02319         dbref vic;
02320         struct malias *m;
02321 
02322         if(!tolist || !*tolist) {
02323                 notify(player, "MAIL: I can't figure out who you want to mail to.");
02324                 return;
02325         }
02326         m = get_malias(player, tolist);
02327 
02328         if(!m) {
02329                 notify_printf(player, "MAIL: Mail alias %s not found.", tolist);
02330                 return;
02331         }
02332         /*
02333          * Parse the player list 
02334          */
02335 
02336         for(k = 0; k < m->numrecep; k++) {
02337                 vic = m->list[k];
02338 
02339                 if(Typeof(vic) == TYPE_PLAYER) {
02340                         send_mail(player, m->list[k], listto, subject, number, flags,
02341                                           silent);
02342                 } else
02343                         send_mail(GOD, GOD, listto, subject,    /*
02344                                                                                                          * Complain 
02345                                                                                                          * about it 
02346                                                                                                          */
02347                                           add_mail_message(player,
02348                                                                            tprintf
02349                                                                            ("Alias Error: Bad Player %d for %s",
02350                                                                                 (dbref) vic, tolist)), 0, silent);
02351         }
02352 }

void do_malias_status ( dbref  player  ) 

Definition at line 3292 of file mail.c.

References ExpMail, ma_size, ma_top, notify, and notify_printf().

Referenced by do_malias().

03293 {
03294         if(!ExpMail(player))
03295                 notify(player, "MAIL: Permission denied.");
03296         else {
03297                 notify_printf(player, "MAIL: Number of mail aliases defined: %d",
03298                                           ma_top);
03299                 notify_printf(player, "MAIL: Allocated slots %d", ma_size);
03300         }
03301 }

void do_malias_switch ( dbref  player,
char *  a1,
char *  a2 
)

Definition at line 2264 of file mail.c.

References do_malias_create(), do_malias_list(), and do_malias_list_all().

Referenced by do_malias().

02265 {
02266         if((!a2 || !*a2) && !(!a1 || !*a1))
02267                 do_malias_list(player, a1);
02268         else if((!*a1 || !a1) && (!*a2 || !a2))
02269                 do_malias_list_all(player);
02270         else
02271                 do_malias_create(player, a1, a2);
02272 }

void do_postpend ( dbref  player,
dbref  cause,
int  key,
char *  text 
)

Definition at line 2978 of file mail.c.

References A_MAILMSG, alloc_lbuf, atr_add_raw(), atr_get(), atr_get_raw(), do_expmail_stop(), Flags2, free_lbuf, confdata::have_mailer, LBUF_SIZE, mudconf, NOTHING, notify, notify_printf(), PLAYER_MAILS, safe_chr, safe_str, and wait_que().

02979 {
02980         char *oldmsg, *newmsg, *bp, *attr;
02981         dbref aowner;
02982         int aflags;
02983 
02984         if(!mudconf.have_mailer) {
02985                 wait_que(player, cause, 0, NOTHING, 0, text, (char **) NULL, 0,
02986                                  (char **) NULL);
02987                 return;
02988         };
02989 
02990         if((*(text + 1) == '-') && !(*(text + 2))) {
02991                 do_expmail_stop(player, 0);
02992                 return;
02993         }
02994         if(Flags2(player) & PLAYER_MAILS) {
02995                 oldmsg = atr_get(player, A_MAILMSG, &aowner, &aflags);
02996                 if(*oldmsg) {
02997                         bp = newmsg = alloc_lbuf("do_postpend");
02998                         safe_str(oldmsg, newmsg, &bp);
02999                         safe_chr(' ', newmsg, &bp);
03000                         safe_str(text + 1, newmsg, &bp);
03001                         *bp = '\0';
03002                         atr_add_raw(player, A_MAILMSG, newmsg);
03003                         free_lbuf(newmsg);
03004                 } else
03005                         atr_add_raw(player, A_MAILMSG, text + 1);
03006 
03007                 free_lbuf(oldmsg);
03008                 attr = atr_get_raw(player, A_MAILMSG);
03009                 notify_printf(player, "%d/%d characters added.",
03010                                           attr ? strlen(attr) : 0, LBUF_SIZE);
03011         } else {
03012                 notify(player, "MAIL: No message in progress.");
03013         }
03014 }

void do_prepend ( dbref  player,
dbref  cause,
int  key,
char *  text 
)

Definition at line 2943 of file mail.c.

References A_MAILMSG, alloc_lbuf, atr_add_raw(), atr_get(), atr_get_raw(), Flags2, free_lbuf, confdata::have_mailer, LBUF_SIZE, mudconf, NOTHING, notify, notify_printf(), PLAYER_MAILS, safe_chr, safe_str, and wait_que().

02944 {
02945         char *oldmsg, *newmsg, *bp, *attr;
02946         dbref aowner;
02947         int aflags;
02948 
02949         if(!mudconf.have_mailer) {
02950                 wait_que(player, cause, 0, NOTHING, 0, text, (char **) NULL, 0,
02951                                  (char **) NULL);
02952                 return;
02953         };
02954 
02955         if(Flags2(player) & PLAYER_MAILS) {
02956                 oldmsg = atr_get(player, A_MAILMSG, &aowner, &aflags);
02957                 if(*oldmsg) {
02958                         bp = newmsg = alloc_lbuf("do_prepend");
02959                         safe_str(text + 1, newmsg, &bp);
02960                         safe_chr(' ', newmsg, &bp);
02961                         safe_str(oldmsg, newmsg, &bp);
02962                         *bp = '\0';
02963                         atr_add_raw(player, A_MAILMSG, newmsg);
02964                         free_lbuf(newmsg);
02965                 } else
02966                         atr_add_raw(player, A_MAILMSG, text + 1);
02967 
02968                 free_lbuf(oldmsg);
02969                 attr = atr_get_raw(player, A_MAILMSG);
02970                 notify_printf(player, "%d/%d characters prepended.",
02971                                           attr ? strlen(attr) : 0, LBUF_SIZE);
02972         } else {
02973                 notify(player, "MAIL: No message in progress.");
02974         }
02975 
02976 }

int dump_mail ( FILE *  fp  ) 

Definition at line 1425 of file mail.c.

References mail_entry::count, DO_WHOLE_DB, mail::from, get_mail_message(), isPlayer, statedata::mail_db_top, statedata::mail_htab, statedata::mail_list, mudstate, mail::next, nhashfind(), mail::number, putref(), putstring(), mail::read, mail::subject, mail::time, mail::to, and mail::tolist.

Referenced by dump_database_internal().

01426 {
01427         struct mail *mp, *mptr;
01428         dbref thing;
01429         int count = 0, i;
01430 
01431         /*
01432          * Write out version number 
01433          */
01434         fprintf(fp, "+V5\n");
01435         putref(fp, mudstate.mail_db_top);
01436         DO_WHOLE_DB(thing) {
01437                 if(isPlayer(thing)) {
01438                         mptr =
01439                                 (struct mail *) nhashfind((int) thing, &mudstate.mail_htab);
01440                         if(mptr != NULL)
01441                                 for(mp = mptr; mp; mp = mp->next) {
01442                                         putref(fp, mp->to);
01443                                         putref(fp, mp->from);
01444                                         putref(fp, mp->number);
01445                                         putstring(fp, mp->tolist);
01446                                         putstring(fp, mp->time);
01447                                         putstring(fp, mp->subject);
01448                                         putref(fp, mp->read);
01449                                         count++;
01450                                 }
01451                 }
01452         }
01453 
01454         fprintf(fp, "*** END OF DUMP ***\n");
01455 
01456         /*
01457          * Add the db of mail messages 
01458          */
01459         for(i = 0; i < mudstate.mail_db_top; i++) {
01460                 if(mudstate.mail_list[i].count > 0) {
01461                         putref(fp, i);
01462                         putstring(fp, get_mail_message(i));
01463                 }
01464         }
01465         fprintf(fp, "+++ END OF DUMP +++\n");
01466 
01467         save_malias(fp);
01468         fflush(fp);
01469 
01470         return (count);
01471 }

static char * get_folder_name ( dbref  ,
int   
) [static]

Definition at line 1627 of file mail.c.

References A_MAILFOLDERS, alloc_lbuf, atr_get(), free_lbuf, LBUF_SIZE, string_match(), and StringCopy.

Referenced by check_mail(), and do_mail_change_folder().

01628 {
01629         static char str[LBUF_SIZE];
01630         char *pat;
01631         static char *old;
01632         char *r, *atrstr;
01633         int flags, len;
01634 
01635         /*
01636          * Get the name of the folder, or "nameless" 
01637          */
01638         pat = alloc_lbuf("get_folder_name");
01639         sprintf(pat, "%d:", fld);
01640         old = NULL;
01641         atrstr = atr_get(player, A_MAILFOLDERS, &player, &flags);
01642         if(!*atrstr) {
01643                 StringCopy(str, "unnamed");
01644                 free_lbuf(pat);
01645                 free_lbuf(atrstr);
01646                 return str;
01647         }
01648         StringCopy(str, atrstr);
01649         old = (char *) string_match(str, pat);
01650         free_lbuf(atrstr);
01651         if(old) {
01652                 r = old + strlen(pat);
01653                 while (*r != ':')
01654                         r++;
01655                 *r = '\0';
01656                 len = strlen(pat);
01657                 free_lbuf(pat);
01658                 return old + len;
01659         } else {
01660                 StringCopy(str, "unnamed");
01661                 free_lbuf(pat);
01662                 return str;
01663         }
01664 }

static int get_folder_number ( dbref  ,
char *   
) [static]

Definition at line 1590 of file mail.c.

References A_MAILFOLDERS, alloc_lbuf, atr_get(), free_lbuf, safe_tprintf_str(), and upcasestr().

Referenced by parse_folder().

01591 {
01592         int aflags;
01593         dbref aowner;
01594         char *atrstr;
01595         char *str, *pat, *res, *p, *bp;
01596 
01597         /* Look up a folder name and return the appopriate number */
01598 
01599         atrstr = atr_get(player, A_MAILFOLDERS, &aowner, &aflags);
01600         if(!*atrstr) {
01601                 free_lbuf(atrstr);
01602                 return -1;
01603         }
01604         str = alloc_lbuf("get_folder_num_str");
01605         bp = pat = alloc_lbuf("get_folder_num_pat");
01606 
01607         strcpy(str, atrstr);
01608         safe_tprintf_str(pat, &bp, ":%s:", upcasestr(name));
01609         res = (char *) strstr(str, pat);
01610         if(!res) {
01611                 free_lbuf(str);
01612                 free_lbuf(pat);
01613                 free_lbuf(atrstr);
01614                 return -1;
01615         }
01616         res += 2 + strlen(name);
01617         p = res;
01618         while (!isspace(*p))
01619                 p++;
01620         p = '\0';
01621         free_lbuf(atrstr);
01622         free_lbuf(str);
01623         free_lbuf(pat);
01624         return atoi(res);
01625 }

INLINE char* get_mail_message ( int  number  ) 

Definition at line 251 of file mail.c.

References delete_mail_message(), LBUF_SIZE, statedata::mail_list, mail_entry::message, mudstate, and StringCopy.

Referenced by do_mail_fwd(), do_mail_list(), do_mail_read(), do_mail_review(), do_mail_stats(), dump_mail(), and fun_mail().

00252 {
00253         static char buff[LBUF_SIZE];
00254 
00255         if(mudstate.mail_list[number].message != NULL) {
00256                 return mudstate.mail_list[number].message;
00257         } else {
00258                 delete_mail_message(number);
00259                 StringCopy(buff,
00260                                    "MAIL: This mail message does not exist in the database. Please alert your admin.");
00261                 return buff;
00262         }
00263 }

struct malias* get_malias ( dbref  player,
char *  alias 
)

Definition at line 2354 of file mail.c.

References ExpMail, GOD, ma_top, malias, malias::name, malias::owner, and x.

Referenced by do_malias_add(), do_malias_chown(), do_malias_create(), do_malias_delete(), do_malias_desc(), do_malias_list(), do_malias_remove(), do_malias_rename(), do_malias_send(), mail_to_list(), and make_numlist().

02355 {
02356         char *mal;
02357         struct malias *m;
02358         int i = 0;
02359         int x = 0;
02360 
02361         if((*alias == '#') && ExpMail(player)) {
02362                 x = atoi(alias + 1);
02363                 if(x < 0 || x >= ma_top)
02364                         return NULL;
02365                 else
02366                         return malias[x];
02367         } else {
02368                 if(*alias != '*')
02369                         return NULL;
02370 
02371                 mal = alias + 1;
02372 
02373                 for(i = 0; i < ma_top; i++) {
02374                         m = malias[i];
02375                         if((m->owner == player) || (m->owner == GOD)) {
02376                                 if(!strcmp(mal, m->name))       /*
02377                                                                                          * Found it! 
02378                                                                                          */
02379                                         return m;
02380                         }
02381                 }
02382         }
02383         return NULL;
02384 }

char* getstring_noalloc ( FILE *  ,
int   
)

Definition at line 1885 of file db.c.

References c, LBUF_SIZE, and safe_chr.

Referenced by db_read(), get_list(), getboolexp1(), load_mail(), and load_restart_db().

01886 {
01887         static char buf[LBUF_SIZE];
01888         char *p;
01889         int c, lastc;
01890 
01891         p = buf;
01892         c = fgetc(f);
01893         if(!new_strings || (c != '"')) {
01894                 ungetc(c, f);
01895                 c = '\0';
01896                 for(;;) {
01897                         lastc = c;
01898                         c = fgetc(f);
01899 
01900                         /*
01901                          * If EOF or null, return 
01902                          */
01903 
01904                         if(!c || (c == EOF)) {
01905                                 *p = '\0';
01906                                 return buf;
01907                         }
01908                         /*
01909                          * If a newline, return if prior char is not a cr. *
01910                          * * * Otherwise * keep on truckin' 
01911                          */
01912 
01913                         if((c == '\n') && (lastc != '\r')) {
01914                                 *p = '\0';
01915                                 return buf;
01916                         }
01917                         safe_chr(c, buf, &p);
01918                 }
01919         } else {
01920                 for(;;) {
01921                         c = fgetc(f);
01922                         if(c == '"') {
01923                                 if((c = fgetc(f)) != '\n')
01924                                         ungetc(c, f);
01925                                 *p = '\0';
01926                                 return buf;
01927                         } else if(c == '\\') {
01928                                 c = fgetc(f);
01929                         }
01930                         if((c == '\0') || (c == EOF)) {
01931                                 *p = '\0';
01932                                 return buf;
01933                         }
01934                         safe_chr(c, buf, &p);
01935                 }
01936         }
01937 }

void init_match ( dbref  player,
const char *  name,
int  type 
)

Referenced by do_boot(), do_chanobj(), do_chown(), do_chownall(), do_chzone(), do_clone(), do_destroy(), do_drop(), do_enter(), do_entrances(), do_examine(), do_fixdb(), do_give(), do_kill(), do_link(), do_lock(), do_look(), do_mail_debug(), do_mail_stats(), do_notify(), do_parent(), do_pemit(), do_pemit_list(), do_setattr(), do_teleport(), do_toad(), do_unlink(), do_use(), do_verb(), do_wait(), fun_locate(), fun_setlock(), give_thing(), init_match_check_keys(), match_affected(), match_controlled(), match_controlled_quiet(), match_examinable(), match_possessed(), match_thing(), parse_attrib_wild(), parse_boolexp_L(), parse_linkable_room(), and parse_thing_slash().

int load_mail ( FILE *  fp  ) 

Definition at line 1473 of file mail.c.

References add_count(), add_mail_message_nosig(), mail::from, getref(), getstring_noalloc(), load_malias(), mail_db_grow(), statedata::mail_htab, mudstate, new_mail_message(), mail::next, nhashadd(), nhashfind(), mail::number, number, mail::prev, mail::read, mail::subject, mail::time, mail::to, mail::tolist, and tprintf().

Referenced by load_game().

01474 {
01475         char nbuf1[8];
01476         int mail_top = 0;
01477         int new = 0;
01478         int pennsub = 0;
01479         int read_tolist = 0;
01480         int read_newdb = 0;
01481         int read_new_strings = 0;
01482         int number = 0;
01483 
01484         struct mail *mp, *mptr;
01485 
01486         /*
01487          * Read the version number 
01488          */
01489         fgets(nbuf1, sizeof(nbuf1), fp);
01490 
01491         if(!strncmp(nbuf1, "+V2", 3)) {
01492                 new = 1;
01493         } else if(!strncmp(nbuf1, "+V3", 3)) {
01494                 new = 1;
01495                 read_tolist = 1;
01496         } else if(!strncmp(nbuf1, "+V4", 3)) {
01497                 new = 1;
01498                 read_tolist = 1;
01499                 read_newdb = 1;
01500         } else if(!strncmp(nbuf1, "+V5", 3)) {
01501                 new = 1;
01502                 read_tolist = 1;
01503                 read_newdb = 1;
01504                 read_new_strings = 1;
01505         } else if(!strncmp(nbuf1, "+1", 2)) {
01506                 pennsub = 1;
01507         }
01508         if(pennsub)
01509                 fgets(nbuf1, sizeof(nbuf1), fp);        /*
01510                                                                                          * Toss away the * *
01511                                                                                          * * number of
01512                                                                                          * messages  *  * *  
01513                                                                                          */
01514         if(read_newdb) {
01515                 mail_top = getref(fp);
01516                 mail_db_grow(mail_top + 1);
01517         } else {
01518                 mail_db_grow(1);
01519         }
01520 
01521         fgets(nbuf1, sizeof(nbuf1), fp);
01522 
01523         while (strncmp(nbuf1, "***", 3)) {
01524                 mp = (struct mail *) malloc(sizeof(struct mail));
01525 
01526                 mp->to = atoi(nbuf1);
01527 
01528                 if(!nhashfind((int) mp->to, &mudstate.mail_htab)) {
01529                         nhashadd((int) mp->to, (int *) mp, &mudstate.mail_htab);
01530                         mp->prev = NULL;
01531                         mp->next = NULL;
01532                 } else {
01533                         for(mptr =
01534                                 (struct mail *) nhashfind((int) mp->to,
01535                                                                                   &mudstate.mail_htab);
01536                                 mptr->next != NULL; mptr = mptr->next);
01537                         mptr->next = mp;
01538                         mp->prev = mptr;
01539                         mp->next = NULL;
01540                 }
01541 
01542                 mp->from = getref(fp);
01543 
01544                 if(read_newdb) {
01545                         mp->number = getref(fp);
01546                         add_count(mp->number);
01547                 }
01548                 if(read_tolist)
01549                         mp->tolist =
01550                                 (char *) strdup(getstring_noalloc(fp, read_new_strings));
01551                 else
01552                         mp->tolist = (char *) strdup(tprintf("%d", mp->to));
01553 
01554                 mp->time = (char *) strdup(getstring_noalloc(fp, read_new_strings));
01555                 if(pennsub)
01556                         mp->subject =
01557                                 (char *) strdup(getstring_noalloc(fp, read_new_strings));
01558                 else if(!new)
01559                         mp->subject = (char *) strdup("No subject");
01560 
01561                 if(!read_newdb) {
01562                         number =
01563                                 add_mail_message_nosig(getstring_noalloc(fp,
01564                                                                                                                  read_new_strings));
01565                         add_count(number);
01566                         mp->number = number;
01567                 }
01568                 if(new)
01569                         mp->subject =
01570                                 (char *) strdup(getstring_noalloc(fp, read_new_strings));
01571                 else if(!pennsub)
01572                         mp->subject = (char *) strdup("No subject");
01573                 mp->read = getref(fp);
01574                 fgets(nbuf1, sizeof(nbuf1), fp);
01575         }
01576 
01577         if(read_newdb) {
01578                 fgets(nbuf1, sizeof(nbuf1), fp);
01579 
01580                 while (strncmp(nbuf1, "+++", 3)) {
01581                         number = atoi(nbuf1);
01582                         new_mail_message(getstring_noalloc(fp, read_new_strings), number);
01583                         fgets(nbuf1, sizeof(nbuf1), fp);
01584                 }
01585         }
01586         load_malias(fp);
01587         return (1);
01588 }

void load_malias ( FILE *  fp  ) 

Definition at line 2545 of file mail.c.

References getref(), and malias_read().

Referenced by load_mail().

02546 {
02547         char buffer[200];
02548 
02549         (void) getref(fp);
02550         if(fscanf(fp, "*** Begin %s ***\n", buffer) == 1 &&
02551            !strcmp(buffer, "MALIAS")) {
02552                 malias_read(fp);
02553         } else {
02554                 fprintf(stderr, "ERROR: Couldn't find Begin MALIAS.\n");
02555                 return;
02556 
02557         }
02558 }

static void mail_db_grow ( int  newtop  )  [static]

Definition at line 79 of file mail.c.

References mail_entry::count, statedata::mail_db_size, statedata::mail_db_top, statedata::mail_list, mail_entry::message, and mudstate.

Referenced by add_mail_message(), add_mail_message_nosig(), and load_mail().

00080 {
00081         int newsize, i;
00082         MENT *newdb;
00083 
00084         if(newtop <= mudstate.mail_db_top) {
00085                 return;
00086         }
00087         if(newtop <= mudstate.mail_db_size) {
00088                 for(i = mudstate.mail_db_top; i < newtop; i++) {
00089                         mudstate.mail_list[i].count = 0;
00090                         mudstate.mail_list[i].message = NULL;
00091                 }
00092                 mudstate.mail_db_top = newtop;
00093                 return;
00094         }
00095         if(newtop <= mudstate.mail_db_size + 100) {
00096                 newsize = mudstate.mail_db_size + 100;
00097         } else {
00098                 newsize = newtop;
00099         }
00100 
00101         newdb = (MENT *) malloc((newsize + 1) * sizeof(MENT));
00102 
00103         if(!newdb)
00104                 abort();
00105 
00106         if(mudstate.mail_list) {
00107                 mudstate.mail_list -= 1;
00108                 bcopy((char *) mudstate.mail_list, (char *) newdb,
00109                           (mudstate.mail_db_top + 1) * sizeof(MENT));
00110                 free(mudstate.mail_list);
00111         }
00112         mudstate.mail_list = newdb + 1;
00113         newdb = NULL;
00114 
00115         for(i = mudstate.mail_db_top; i < newtop; i++) {
00116                 mudstate.mail_list[i].count = 0;
00117                 mudstate.mail_list[i].message = NULL;
00118         }
00119         mudstate.mail_db_top = newtop;
00120         mudstate.mail_db_size = newsize;
00121 }

struct mail* mail_fetch ( dbref  player,
int  num 
)

Definition at line 863 of file mail.c.

References Folder, statedata::mail_htab, mudstate, mail::next, nhashfind(), and player_folder().

Referenced by do_mail_fwd(), fun_mail(), fun_mailfrom(), and make_numlist().

00864 {
00865         struct mail *mp;
00866         int i = 0;
00867 
00868         for(mp = (struct mail *) nhashfind((int) player, &mudstate.mail_htab);
00869                 mp; mp = mp->next) {
00870                 if(Folder(mp) == player_folder(player)) {
00871                         i++;
00872                         if(i == num)
00873                                 return mp;
00874                 }
00875         }
00876         return NULL;
00877 }

static char * mail_list_time ( const char *   )  [static]

Definition at line 728 of file mail.c.

References alloc_lbuf.

Referenced by do_mail_list().

00729 {
00730         char *new;
00731         char *p, *q;
00732         int i;
00733 
00734         p = (char *) the_time;
00735         q = new = alloc_lbuf("mail_list_time");
00736         if(!p || !*p) {
00737                 *new = '\0';
00738                 return new;
00739         }
00740         /*
00741          * Format of the_time is: day mon dd hh:mm:ss yyyy 
00742          */
00743         /*
00744          * Chop out :ss 
00745          */
00746         for(i = 0; i < 16; i++) {
00747                 if(*p)
00748                         *q++ = *p++;
00749         }
00750 
00751         for(i = 0; i < 3; i++) {
00752                 if(*p)
00753                         p++;
00754         }
00755 
00756         for(i = 0; i < 5; i++) {
00757                 if(*p)
00758                         *q++ = *p++;
00759         }
00760 
00761         *q = '\0';
00762         return new;
00763 }

static int mail_match ( struct mail ,
struct  mail_selector,
int   
) [static]

Definition at line 1790 of file mail.c.

References alloc_lbuf, mail_selector::day_comp, mail_selector::days, do_convtime(), mail_selector::flags, free_lbuf, mail::from, mail_selector::high, log_text(), mail_selector::low, M_ALL, M_MSUNREAD, mail_selector::player, mail::read, Read, sign(), StringCopy, mail::time, and time().

Referenced by do_mail_file(), do_mail_flags(), do_mail_list(), do_mail_read(), do_mail_retract(), and do_mail_review().

01791 {
01792         time_t now, msgtime, diffdays;
01793         char *msgtimestr;
01794         struct tm *msgtm;
01795         mail_flag mpflag;
01796 
01797         /*
01798          * Does a piece of mail match the mail_selector? 
01799          */
01800         if(ms.low && num < ms.low)
01801                 return 0;
01802         if(ms.high && num > ms.high)
01803                 return 0;
01804         if(ms.player && mp->from != ms.player)
01805                 return 0;
01806         mpflag = Read(mp) ? mp->read : (mp->read | M_MSUNREAD);
01807         if(!(ms.flags & M_ALL) && !(ms.flags & mpflag))
01808                 return 0;
01809         if(ms.days != -1) {
01810                 /*
01811                  * Get the time now, subtract mp->time, and compare the * * * 
01812                  * results with * ms.days (in manner of ms.day_comp) 
01813                  */
01814                 time(&now);
01815                 msgtm = (struct tm *) malloc(sizeof(struct tm));
01816 
01817                 if(!msgtm) {
01818                         /*
01819                          * Ugly malloc failure 
01820                          */
01821                         log_text("MAIL: Couldn't malloc struct tm!");
01822                         return 0;
01823                 }
01824                 msgtimestr = alloc_lbuf("mail_match");
01825                 StringCopy(msgtimestr, mp->time);
01826                 if(do_convtime(msgtimestr, msgtm)) {
01827                         msgtime = timelocal(msgtm);
01828                         free(msgtm);
01829                         diffdays = (now - msgtime) / 86400;
01830                         free_lbuf(msgtimestr);
01831                         if(sign(diffdays - ms.days) != ms.day_comp) {
01832                                 return 0;
01833                         }
01834                 } else {
01835                         free(msgtm);
01836                         free_lbuf(msgtimestr);
01837                         return 0;
01838                 }
01839         }
01840         return 1;
01841 }

void mail_to_list ( dbref  ,
char *  ,
char *  ,
char *  ,
int  ,
int   
) [static]

Definition at line 2842 of file mail.c.

References add_mail_message(), alloc_lbuf, do_malias_send(), free_lbuf, get_malias(), malias, NOTHING, number, send_mail(), StringCopy, and mail::tolist.

Referenced by do_expmail_stop(), and do_mail_quick().

02844 {
02845         char *head, *tail, spot, *tolist;
02846         struct malias *m;
02847         dbref target;
02848         int number;
02849 
02850         if(!list) {
02851                 return;
02852         }
02853         if(!*list) {
02854                 free_lbuf(list);
02855                 return;
02856         }
02857         tolist = alloc_lbuf("mail_to_list");
02858         StringCopy(tolist, list);
02859 
02860         number = add_mail_message(player, message);
02861 
02862         head = (char *) list;
02863         while (head && *head) {
02864                 while (*head == ' ')
02865                         head++;
02866 
02867                 tail = head;
02868                 while (*tail && (*tail != ' ')) {
02869                         if(*tail == '"') {
02870                                 head++;
02871                                 tail++;
02872                                 while (*tail && (*tail != '"'))
02873                                         tail++;
02874                         }
02875                         if(*tail)
02876                                 tail++;
02877                 }
02878                 tail--;
02879                 if(*tail != '"')
02880                         tail++;
02881                 spot = *tail;
02882                 *tail = 0;
02883 
02884                 if(*head == '*') {
02885                         m = get_malias(player, head);
02886                         if(!m) {
02887                                 free_lbuf(list);
02888                                 free_lbuf(tolist);
02889                                 return;
02890                         }
02891                         do_malias_send(player, head, tolist, subject, number, flags,
02892                                                    silent);
02893                 } else {
02894                         target = atoi(head);
02895                         if(target != NOTHING) {
02896                                 send_mail(player, target, tolist, subject, number, flags,
02897                                                   silent);
02898                         }
02899                 }
02900 
02901                 /*
02902                  * Get the next recip 
02903                  */
02904                 *tail = spot;
02905                 head = tail;
02906                 if(*head == '"')
02907                         head++;
02908         }
02909         free_lbuf(tolist);
02910         free_lbuf(list);
02911 }

static void make_mail_freelist (  )  [static]

Definition at line 128 of file mail.c.

References statedata::mail_db_top, statedata::mail_freelist, statedata::mail_list, mail_entry::message, and mudstate.

Referenced by add_mail_message(), and add_mail_message_nosig().

00129 {
00130         int i;
00131 
00132         for(i = 0; i < mudstate.mail_db_top; i++) {
00133                 if(mudstate.mail_list[i].message == NULL) {
00134                         mudstate.mail_freelist = i;
00135                         return;
00136                 }
00137         }
00138 
00139         mail_db_grow(i + 1);
00140         mudstate.mail_freelist = i;
00141 }

static char * make_namelist ( dbref  ,
char *   
) [static]

Definition at line 2697 of file mail.c.

References alloc_lbuf, free_lbuf, Name(), names, safe_str, StringCopy, and strtok().

Referenced by do_expmail_start(), do_mail_cc(), do_mail_proof(), and do_mail_read().

02698 {
02699         char *names, *oldarg;
02700         char *bp, *p;
02701 
02702         oldarg = alloc_lbuf("make_namelist.oldarg");
02703         names = alloc_lbuf("make_namelist.names");
02704         bp = names;
02705 
02706         StringCopy(oldarg, arg);
02707 
02708         for(p = (char *) strtok(oldarg, " "); p != NULL;
02709                 p = (char *) strtok(NULL, " ")) {
02710                 if(*p == '*') {
02711                         safe_str(p, names, &bp);
02712                         safe_str(", ", names, &bp);
02713                 } else {
02714                         safe_str(Name(atoi(p)), names, &bp);
02715                         safe_str(", ", names, &bp);
02716                 }
02717         }
02718         *(bp - 2) = '\0';
02719         free_lbuf(oldarg);
02720         return names;
02721 }

static char * make_numlist ( dbref  ,
char *   
) [static]

Definition at line 2723 of file mail.c.

References alloc_lbuf, free_lbuf, mail::from, get_malias(), lookup_player(), mail_fetch(), malias, MBUF_SIZE, NOTHING, notify, notify_printf(), safe_chr, and safe_str.

Referenced by do_expmail_start(), do_mail_cc(), and do_mail_quick().

02724 {
02725         char *head, *tail, spot;
02726         static char *numbuf;
02727         static char buf[MBUF_SIZE];
02728         char *numbp;
02729         struct malias *m;
02730         struct mail *temp;
02731         dbref target;
02732         int num;
02733 
02734         numbuf = alloc_lbuf("make_numlist");
02735         numbp = numbuf;
02736         *numbp = '\0';
02737 
02738         head = (char *) arg;
02739         while (head && *head) {
02740                 while (*head == ' ')
02741                         head++;
02742 
02743                 tail = head;
02744                 while (*tail && (*tail != ' ')) {
02745                         if(*tail == '"') {
02746                                 head++;
02747                                 tail++;
02748                                 while (*tail && (*tail != '"'))
02749                                         tail++;
02750                         }
02751                         if(*tail)
02752                                 tail++;
02753                 }
02754                 tail--;
02755                 if(*tail != '"')
02756                         tail++;
02757                 spot = *tail;
02758                 *tail = 0;
02759 
02760                 num = atoi(head);
02761                 if(num) {
02762                         temp = mail_fetch(player, num);
02763                         if(!temp) {
02764                                 notify(player, "MAIL: You can't reply to nonexistent mail.");
02765                                 free_lbuf(numbuf);
02766                                 return NULL;
02767                         }
02768                         sprintf(buf, "%d ", temp->from);
02769                         safe_str(buf, numbuf, &numbp);
02770                 } else if(*head == '*') {
02771                         m = get_malias(player, head);
02772                         if(!m) {
02773                                 notify_printf(player, "MAIL: Alias '%s' does not exist.",
02774                                                           head);
02775                                 free_lbuf(numbuf);
02776                                 return NULL;
02777                         }
02778                         safe_str(head, numbuf, &numbp);
02779                         safe_chr(' ', numbuf, &numbp);
02780                 } else {
02781                         target = lookup_player(player, head, 1);
02782                         if(target != NOTHING) {
02783                                 sprintf(buf, "%d ", target);
02784                                 safe_str(buf, numbuf, &numbp);
02785                         } else {
02786                                 notify_printf(player, "MAIL: '%s' does not exist.", head);
02787                                 free_lbuf(numbuf);
02788                                 return NULL;
02789                         }
02790                 }
02791 
02792                 /*
02793                  * Get the next recip 
02794                  */
02795                 *tail = spot;
02796                 head = tail;
02797                 if(*head == '"')
02798                         head++;
02799         }
02800 
02801         if(!*numbuf) {
02802                 notify(player, "MAIL: No players specified.");
02803                 free_lbuf(numbuf);
02804                 return NULL;
02805         } else {
02806                 *(numbp - 1) = '\0';
02807                 return numbuf;
02808         }
02809 }

void malias_read ( FILE *  fp  ) 

Definition at line 2567 of file mail.c.

References Alive, malias::desc, getref(), Good_obj, malias::list, ma_size, ma_top, malias, malias::name, malias::numrecep, malias::owner, and StringCopy.

Referenced by load_malias().

02568 {
02569         int i, j;
02570         char buffer[1000];
02571         struct malias *m;
02572 
02573         fscanf(fp, "%d\n", &ma_top);
02574 
02575         ma_size = ma_top;
02576 
02577         if(ma_top > 0)
02578                 malias = (struct malias **) malloc(sizeof(struct malias *) * ma_size);
02579 
02580         else
02581                 malias = NULL;
02582 
02583         for(i = 0; i < ma_top; i++) {
02584                 malias[i] = (struct malias *) malloc(sizeof(struct malias));
02585 
02586                 m = (struct malias *) malias[i];
02587 
02588                 fscanf(fp, "%d %d\n", &(m->owner), &(m->numrecep));
02589 
02590                 fscanf(fp, "%[^\n]\n", buffer);
02591                 m->name = (char *) malloc(strlen(buffer) - 1);
02592                 StringCopy(m->name, buffer + 2);
02593                 fscanf(fp, "%[^\n]\n", buffer);
02594                 m->desc = (char *) malloc(strlen(buffer) - 1);
02595                 StringCopy(m->desc, buffer + 2);
02596 
02597                 if(m->numrecep > 0) {
02598 
02599                         for(j = 0; j < m->numrecep; j++) {
02600                                 m->list[j] = getref(fp);
02601 
02602                         }
02603                 } else
02604                         m->list[0] = 0;
02605 
02606         }
02607         /* compress aliases [to prevent junk] */
02608         for(i = 0; i < ma_top; i++)
02609                 if(!Good_obj(malias[i]->owner) || !Alive(malias[i]->owner)) {
02610                         if(i != ma_top - 1)
02611                                 memcpy(malias[i], malias[ma_top - 1], sizeof(struct malias));;
02612                         ma_top--;
02613                 }
02614 }

void malias_write ( FILE *  fp  ) 

Definition at line 2616 of file mail.c.

References malias::desc, malias::list, ma_top, malias, malias::name, malias::numrecep, and malias::owner.

Referenced by save_malias().

02617 {
02618         int i, j;
02619         struct malias *m;
02620 
02621         fprintf(fp, "%d\n", ma_top);
02622 
02623         for(i = 0; i < ma_top; i++) {
02624                 m = malias[i];
02625                 fprintf(fp, "%d %d\n", m->owner, m->numrecep);
02626                 fprintf(fp, "N:%s\n", m->name);
02627                 fprintf(fp, "D:%s\n", m->desc);
02628                 for(j = 0; j < m->numrecep; j++)
02629                         fprintf(fp, "%d\n", m->list[j]);
02630         }
02631 }

void match_absolute ( void   ) 

Definition at line 170 of file match.c.

Referenced by do_boot(), do_chown(), do_chownall(), do_enter(), do_get(), do_give(), do_kill(), do_look(), do_mail_debug(), do_mail_stats(), do_toad(), do_use(), fun_locate(), and match_everything().

00171 {
00172         if(md.confidence >= CON_DBREF)
00173                 return;
00174         if(Good_obj(md.absolute_form))
00175                 promote_match(md.absolute_form, CON_DBREF);
00176 }

dbref match_result ( void   ) 

Definition at line 410 of file match.c.

Referenced by dispatched_match_result(), do_chanobj(), do_chown(), do_drop(), do_get(), do_give(), do_kill(), do_lock(), do_look(), do_mail_debug(), do_mail_stats(), do_move(), do_pemit(), do_pemit_list(), do_teleport(), do_unlink(), fun_locate(), fun_setlock(), give_thing(), match_controlled_quiet(), match_possessed(), noisy_match_result(), parse_attrib_wild(), parse_boolexp_L(), parse_linkable_room(), and parse_thing_slash().

00411 {
00412         switch (md.count) {
00413         case 0:
00414                 return NOTHING;
00415         case 1:
00416                 return md.match;
00417         default:
00418                 return AMBIGUOUS;
00419         }
00420 }

static void new_mail_message ( char *  message,
int  number 
) [static]

Definition at line 216 of file mail.c.

References statedata::mail_list, mail_entry::message, and mudstate.

Referenced by load_mail().

00217 {
00218         mudstate.mail_list[number].message = (char *) strdup(message);
00219 }

static int parse_folder ( dbref  ,
char *   
) [static]

Definition at line 1766 of file mail.c.

References get_folder_number(), and MAX_FOLDERS.

Referenced by do_mail_change_folder(), and do_mail_file().

01767 {
01768         int fnum;
01769 
01770         /*
01771          * Given a string, return a folder #, or -1 The string is just a * *
01772          * * number, * for now. Later, this will be where named folders are * 
01773          * *  * handled 
01774          */
01775         if(!folder_string || !*folder_string)
01776                 return -1;
01777         if(isdigit(*folder_string)) {
01778                 fnum = atoi(folder_string);
01779                 if((fnum < 0) || (fnum > MAX_FOLDERS))
01780                         return -1;
01781                 else
01782                         return fnum;
01783         }
01784         /*
01785          * Handle named folders here 
01786          */
01787         return get_folder_number(player, folder_string);
01788 }

static int parse_msglist ( char *  ,
struct mail_selector ,
dbref   
) [static]

Definition at line 1843 of file mail.c.

References mail_selector::day_comp, mail_selector::days, mail_selector::flags, Good_obj, mail_selector::high, LBUF_SIZE, lookup_player(), mail_selector::low, M_ALL, M_CLEARED, M_ISREAD, M_MASS, M_MSUNREAD, M_TAG, M_URGENT, NOTHING, notify, mail_selector::player, seek_char(), and StringCopyTrunc.

Referenced by do_mail_file(), do_mail_flags(), do_mail_list(), do_mail_read(), do_mail_retract(), and do_mail_review().

01845 {
01846         char *p, *q;
01847         char tbuf1[LBUF_SIZE];
01848 
01849         /*
01850          * Take a message list, and return the appropriate mail_selector * *
01851          * * setup. For * now, msglists are quite restricted. That'll change
01852          * * * * once all this is * working. Returns 0 if couldn't parse, and
01853          * * also * * notifys player of why. 
01854          */
01855         /*
01856          * Initialize the mail selector - this matches all messages 
01857          */
01858         ms->low = 0;
01859         ms->high = 0;
01860         ms->flags = 0x0FFF | M_MSUNREAD;
01861         ms->player = 0;
01862         ms->days = -1;
01863         ms->day_comp = 0;
01864         /*
01865          * Now, parse the message list 
01866          */
01867         if(!msglist || !*msglist) {
01868                 /*
01869                  * All messages 
01870                  */
01871                 return 1;
01872         }
01873         /*
01874          * Don't mess with msglist itself 
01875          */
01876         StringCopyTrunc(tbuf1, msglist, LBUF_SIZE - 1);
01877         p = tbuf1;
01878         while (p && *p && isspace(*p))
01879                 p++;
01880         if(!p || !*p) {
01881                 return 1;                               /*
01882                                                                  * all messages 
01883                                                                  */
01884         }
01885         if(isdigit(*p)) {
01886                 /*
01887                  * Message or range 
01888                  */
01889                 q = seek_char(p, '-');
01890                 if(*q) {
01891                         /*
01892                          * We have a subrange, split it up and test to see if 
01893                          * 
01894                          * *  * *  * * it is valid 
01895                          */
01896                         *q++ = '\0';
01897                         ms->low = atoi(p);
01898                         if(ms->low <= 0) {
01899                                 notify(player, "MAIL: Invalid message range");
01900                                 return 0;
01901                         }
01902                         if(!q || !*q) {
01903                                 /*
01904                                  * Unbounded range 
01905                                  */
01906                                 ms->high = 0;
01907                         } else {
01908                                 ms->high = atoi(q);
01909                                 if((ms->low > ms->high) || (ms->high <= 0)) {
01910                                         notify(player, "MAIL: Invalid message range");
01911                                         return 0;
01912                                 }
01913                         }
01914                 } else {
01915                         /*
01916                          * A single message 
01917                          */
01918                         ms->low = ms->high = atoi(p);
01919                 }
01920         } else {
01921                 switch (*p) {
01922                 case '-':                               /*
01923                                                                  * Range with no start 
01924                                                                  */
01925                         p++;
01926                         if(!p || !*p) {
01927                                 notify(player, "MAIL: Invalid message range");
01928                                 return 0;
01929                         }
01930                         ms->high = atoi(p);
01931                         if(ms->high <= 0) {
01932                                 notify(player, "MAIL: Invalid message range");
01933                                 return 0;
01934                         }
01935                         break;
01936                 case '~':                               /*
01937                                                                  * exact # of days old 
01938                                                                  */
01939                         p++;
01940                         if(!p || !*p) {
01941                                 notify(player, "MAIL: Invalid age");
01942                                 return 0;
01943                         }
01944                         ms->day_comp = 0;
01945                         ms->days = atoi(p);
01946                         if(ms->days < 0) {
01947                                 notify(player, "MAIL: Invalid age");
01948                                 return 0;
01949                         }
01950                         break;
01951                 case '<':                               /*
01952                                                                  * less than # of days old 
01953                                                                  */
01954                         p++;
01955                         if(!p || !*p) {
01956                                 notify(player, "MAIL: Invalid age");
01957                                 return 0;
01958                         }
01959                         ms->day_comp = -1;
01960                         ms->days = atoi(p);
01961                         if(ms->days < 0) {
01962                                 notify(player, "MAIL: Invalid age");
01963                                 return 0;
01964                         }
01965                         break;
01966                 case '>':                               /*
01967                                                                  * greater than # of days old 
01968                                                                  */
01969                         p++;
01970                         if(!p || !*p) {
01971                                 notify(player, "MAIL: Invalid age");
01972                                 return 0;
01973                         }
01974                         ms->day_comp = 1;
01975                         ms->days = atoi(p);
01976                         if(ms->days < 0) {
01977                                 notify(player, "MAIL: Invalid age");
01978                                 return 0;
01979                         }
01980                         break;
01981                 case '#':                               /*
01982                                                                  * From db# 
01983                                                                  */
01984                         p++;
01985                         if(!p || !*p) {
01986                                 notify(player, "MAIL: Invalid dbref #");
01987                                 return 0;
01988                         }
01989                         ms->player = atoi(p);
01990                         if(!Good_obj(ms->player) || !(ms->player)) {
01991                                 notify(player, "MAIL: Invalid dbref #");
01992                                 return 0;
01993                         }
01994                         break;
01995                 case '*':                               /*
01996                                                                  * From player name 
01997                                                                  */
01998                         p++;
01999                         if(!p || !*p) {
02000                                 notify(player, "MAIL: Invalid player");
02001                                 return 0;
02002                         }
02003                         ms->player = lookup_player(player, p, 1);
02004                         if(ms->player == NOTHING) {
02005                                 notify(player, "MAIL: Invalid player");
02006                                 return 0;
02007                         }
02008                         break;
02009 
02010 /*
02011  * case 'a':
02012  * case 'A':            all messages, all folders 
02013  */
02014                         ms->flags = M_ALL;
02015                         break;                          /*
02016                                                                  *  FIX THIS 
02017                                                                  */
02018                 case 'u':                               /*
02019                                                                  * Urgent, Unread 
02020                                                                  */
02021                 case 'U':
02022                         p++;
02023                         if(!p || !*p) {
02024                                 notify(player, "MAIL: U is ambiguous (urgent or unread?)");
02025                                 return 0;
02026                         }
02027                         switch (*p) {
02028                         case 'r':                       /*
02029                                                                  * Urgent 
02030                                                                  */
02031                         case 'R':
02032                                 ms->flags = M_URGENT;
02033                                 break;
02034                         case 'n':                       /*
02035                                                                  * Unread 
02036                                                                  */
02037                         case 'N':
02038                                 ms->flags = M_MSUNREAD;
02039                                 break;
02040                         default:                        /*
02041                                                                  * bad 
02042                                                                  */
02043                                 notify(player, "MAIL: Invalid message specification");
02044                                 return 0;
02045                                 break;
02046                         }
02047                         break;
02048                 case 'r':                               /*
02049                                                                  * read 
02050                                                                  */
02051                 case 'R':
02052                         ms->flags = M_ISREAD;
02053                         break;
02054                 case 'c':                               /*
02055                                                                  * cleared 
02056                                                                  */
02057                 case 'C':
02058                         ms->flags = M_CLEARED;
02059                         break;
02060                 case 't':                               /*
02061                                                                  * tagged 
02062                                                                  */
02063                 case 'T':
02064                         ms->flags = M_TAG;
02065                         break;
02066                 case 'm':
02067                 case 'M':                               /*
02068                                                                  * Mass, me 
02069                                                                  */
02070                         p++;
02071                         if(!p || !*p) {
02072                                 notify(player, "MAIL: M is ambiguous (mass or me?)");
02073                                 return 0;
02074                         }
02075                         switch (*p) {
02076                         case 'a':
02077                         case 'A':
02078                                 ms->flags = M_MASS;
02079                                 break;
02080                         case 'e':
02081                         case 'E':
02082                                 ms->player = player;
02083                                 break;
02084                         default:
02085                                 notify(player, "MAIL: Invalid message specification");
02086                                 return 0;
02087                                 break;
02088                         }
02089                         break;
02090                 default:                                /*
02091                                                                  * Bad news 
02092                                                                  */
02093                         notify(player, "MAIL: Invalid message specification");
02094                         return 0;
02095                         break;
02096                 }
02097         }
02098         return 1;
02099 }

static int player_folder ( dbref   )  [static]

Definition at line 1723 of file mail.c.

References A_MAILCURF, atr_pget(), free_lbuf, number, and set_player_folder().

Referenced by do_mail_change_folder(), do_mail_file(), do_mail_flags(), do_mail_list(), do_mail_read(), and mail_fetch().

01724 {
01725         /*
01726          * Return the player's current folder number. If they don't have one, 
01727          * 
01728          * *  * *  * * set * it to 0 
01729          */
01730         int flags, number;
01731         char *atrstr;
01732 
01733         atrstr = atr_pget(player, A_MAILCURF, &player, &flags);
01734         if(!*atrstr) {
01735                 free_lbuf(atrstr);
01736                 set_player_folder(player, 0);
01737                 return 0;
01738         }
01739         number = atoi(atrstr);
01740         free_lbuf(atrstr);
01741         return number;
01742 }

void putstring ( FILE *  f,
const char *  s 
)

Definition at line 1867 of file db.c.

Referenced by db_write_object(), dump_mail(), and dump_restart_db().

01868 {
01869         putc('"', f);
01870 
01871         while (s && *s) {
01872                 switch (*s) {
01873                 case '\\':
01874                 case '"':
01875                         putc('\\', f);
01876                 default:
01877                         putc(*s, f);
01878                 }
01879                 s++;
01880         }
01881         putc('"', f);
01882         putc('\n', f);
01883 }

void save_malias ( FILE *  fp  ) 

Definition at line 2560 of file mail.c.

References malias_write().

02561 {
02562 
02563         fprintf(fp, "*** Begin MALIAS ***\n");
02564         malias_write(fp);
02565 }

static void send_mail ( dbref  ,
dbref  ,
const char *  ,
const char *  ,
int  ,
mail_flag  ,
int   
) [static]

Definition at line 925 of file mail.c.

References A_AMAIL, A_MAIL, add_count(), delete_mail_message(), did_it(), mail::from, M_FMASK, statedata::mail_htab, mudstate, Name(), mail::next, nhashadd(), nhashfind(), NOTHING, notify, notify_printf(), mail::number, mail::prev, mail::read, StringCopy, mail::subject, mail::time, time(), mail::to, mail::tolist, TYPE_PLAYER, and Typeof.

Referenced by do_malias_send(), and mail_to_list().

00928 {
00929         struct mail *newp;
00930         struct mail *mp;
00931         time_t tt;
00932         char tbuf1[30];
00933 
00934         if(Typeof(target) != TYPE_PLAYER) {
00935                 notify(player, "MAIL: You cannot send mail to non-existent people.");
00936                 delete_mail_message(number);
00937                 return;
00938         }
00939         tt = time(NULL);
00940         StringCopy(tbuf1, ctime(&tt));
00941         tbuf1[strlen(tbuf1) - 1] = '\0';        /*
00942                                                                                  * whack the newline 
00943                                                                                  */
00944 
00945         /*
00946          * initialize the appropriate fields 
00947          */
00948         newp = (struct mail *) malloc(sizeof(struct mail));
00949 
00950         newp->to = target;
00951         newp->from = player;
00952         newp->tolist = (char *) strdup((char *) tolist);
00953 
00954         newp->number = number;
00955         add_count(number);
00956 
00957         newp->time = (char *) strdup(tbuf1);
00958         newp->subject = (char *) strdup(subject);
00959         newp->read = flags & M_FMASK;   /*
00960                                                                          * Send to folder 0 
00961                                                                          */
00962 
00963         /*
00964          * if this is the first message, it is the head and the tail 
00965          */
00966         if(!nhashfind((int) target, &mudstate.mail_htab)) {
00967                 nhashadd((int) target, (int *) newp, &mudstate.mail_htab);
00968                 newp->next = NULL;
00969                 newp->prev = NULL;
00970         } else {
00971                 for(mp =
00972                         (struct mail *) nhashfind((int) target, &mudstate.mail_htab);
00973                         mp->next; mp = mp->next);
00974 
00975                 mp->next = newp;
00976                 newp->next = NULL;
00977                 newp->prev = mp;
00978         }
00979 
00980         /*
00981          * notify people 
00982          */
00983         if(!silent)
00984                 notify_printf(player, "MAIL: You sent your message to %s.",
00985                                           Name(target));
00986 
00987         notify_printf(target, "MAIL: You have a new message from %s.",
00988                                   Name(player));
00989         did_it(player, target, A_MAIL, NULL, (int) NULL, NULL, A_AMAIL, NULL,
00990                    NOTHING);
00991         return;
00992 }

void set_player_folder ( dbref  player,
int  fnum 
)

Definition at line 1744 of file mail.c.

References A_MAILCURF, AF_LOCK, AF_NOPROG, AF_ODARK, AF_WIZARD, alloc_lbuf, atr_add(), atr_num(), attr::flags, free_lbuf, and GOD.

Referenced by do_mail_change_folder(), and player_folder().

01745 {
01746         /*
01747          * Set a player's folder to fnum 
01748          */
01749         ATTR *a;
01750         char *tbuf1;
01751 
01752         tbuf1 = alloc_lbuf("set_player_folder");
01753         sprintf(tbuf1, "%d", fnum);
01754         a = (ATTR *) atr_num(A_MAILCURF);
01755         if(a)
01756                 atr_add(player, A_MAILCURF, tbuf1, GOD, a->flags);
01757         else {                                          /*
01758                                                                  * Shouldn't happen, but... 
01759                                                                  */
01760                 atr_add(player, A_MAILCURF, tbuf1, GOD,
01761                                 AF_ODARK | AF_WIZARD | AF_NOPROG | AF_LOCK);
01762         }
01763         free_lbuf(tbuf1);
01764 }

static int sign ( int   )  [static]

Definition at line 2253 of file mail.c.

Referenced by do_chmod_macro(), growSnow(), and mail_match().

02254 {
02255         if(x == 0) {
02256                 return 0;
02257         } else if(x < 0) {
02258                 return -1;
02259         } else {
02260                 return 1;
02261         }
02262 }

static char * status_chars ( struct mail  )  [static]

Definition at line 2156 of file mail.c.

References Cleared, Forward, M_Safe, Mass, Read, StringCopy, Tagged, and Urgent.

Referenced by do_mail_list(), and do_mail_review().

02157 {
02158         /*
02159          * Return a short description of message flags 
02160          */
02161         static char res[10];
02162         char *p;
02163 
02164         StringCopy(res, "");
02165         p = res;
02166         *p++ = Read(mp) ? '-' : 'N';
02167         *p++ = M_Safe(mp) ? 'S' : '-';
02168         *p++ = Cleared(mp) ? 'C' : '-';
02169         *p++ = Urgent(mp) ? 'U' : '-';
02170         *p++ = Mass(mp) ? 'M' : '-';
02171         *p++ = Forward(mp) ? 'F' : '-';
02172         *p++ = Tagged(mp) ? '+' : '-';
02173         *p = '\0';
02174         return res;
02175 }

static char * status_string ( struct mail  )  [static]

Definition at line 2177 of file mail.c.

References alloc_lbuf, Cleared, Forward, M_Safe, Mass, Read, StringCopy, Tagged, and Urgent.

Referenced by do_mail_read(), and do_mail_review().

02178 {
02179         /*
02180          * Return a longer description of message flags 
02181          */
02182         char *tbuf1;
02183 
02184         tbuf1 = alloc_lbuf("status_string");
02185         StringCopy(tbuf1, "");
02186         if(Read(mp))
02187                 strcat(tbuf1, "Read ");
02188         else
02189                 strcat(tbuf1, "Unread ");
02190         if(Cleared(mp))
02191                 strcat(tbuf1, "Cleared ");
02192         if(Urgent(mp))
02193                 strcat(tbuf1, "Urgent ");
02194         if(Mass(mp))
02195                 strcat(tbuf1, "Mass ");
02196         if(Forward(mp))
02197                 strcat(tbuf1, "Fwd ");
02198         if(Tagged(mp))
02199                 strcat(tbuf1, "Tagged ");
02200         if(M_Safe(mp))
02201                 strcat(tbuf1, "Safe");
02202         return tbuf1;
02203 }

char* upcasestr ( char *   ) 

Definition at line 186 of file stringutil.c.

References ToUpper.

00187 {
00188         char *p;
00189 
00190         for(p = s; p && *p; p++)
00191                 *p = ToUpper(*p);
00192         return s;
00193 }

void urgent_mail ( dbref  player,
int  folder,
int *  ucount 
)

Definition at line 908 of file mail.c.

References Folder, statedata::mail_htab, mudstate, mail::next, nhashfind(), Read, and Urgent.

Referenced by check_mail().

00909 {
00910         struct mail *mp;
00911         int uc;
00912 
00913         uc = 0;
00914 
00915         for(mp = (struct mail *) nhashfind((int) player, &mudstate.mail_htab);
00916                 mp; mp = mp->next) {
00917                 if(Folder(mp) == folder) {
00918                         if(!(Read(mp)) && (Urgent(mp)))
00919                                 uc++;
00920                 }
00921         }
00922         *ucount = uc;
00923 }


Variable Documentation

int ma_size = 0

Definition at line 65 of file mail.c.

Referenced by do_malias_create(), do_malias_status(), and malias_read().

int ma_top = 0

Definition at line 66 of file mail.c.

Referenced by do_malias_adminlist(), do_malias_create(), do_malias_delete(), do_malias_list_all(), do_malias_status(), get_malias(), malias_read(), and malias_write().

struct malias** malias

Definition at line 68 of file mail.c.

Referenced by do_malias_add(), do_malias_adminlist(), do_malias_chown(), do_malias_create(), do_malias_delete(), do_malias_desc(), do_malias_list(), do_malias_list_all(), do_malias_remove(), do_malias_rename(), do_malias_send(), get_malias(), mail_to_list(), make_numlist(), malias_read(), and malias_write().

char msgbuff[LBUF_SIZE+(LBUF_SIZE >> 1)+1]

Definition at line 23 of file mail.c.

Referenced by do_mail_review().


Generated on Mon May 28 04:25:45 2007 for BattletechMUX by  doxygen 1.4.7