~ubuntu-branches/ubuntu/utopic/tinymux/utopic

« back to all changes in this revision

Viewing changes to src/mail.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ervin Hearn III
  • Date: 2008-04-11 23:18:25 UTC
  • mfrom: (1.1.5 upstream) (6.1.1 gutsy)
  • Revision ID: james.westby@ubuntu.com-20080411231825-1pq4trckagyk8roo
Tags: 2.6.5.27-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// mail.cpp
2
2
//
3
 
// $Id: mail.cpp,v 1.54 2006/02/02 23:02:59 sdennis Exp $
 
3
// $Id: mail.cpp 3051 2007-12-30 06:36:17Z brazilofmux $
4
4
//
5
5
// This code was taken from Kalkin's DarkZone code, which was
6
6
// originally taken from PennMUSH 1.50 p10, and has been heavily modified
24
24
#define SIZEOF_MALIASDESC (WIDTHOF_MALIASDESC*2)
25
25
 
26
26
#define MAX_MALIAS_MEMBERSHIP 100
27
 
struct malias
 
27
typedef struct malias
28
28
{
29
 
    int owner;
 
29
    int  owner;
 
30
    int  numrecep;
30
31
    char *name;
31
32
    char *desc;
32
 
    int desc_width; // The visual width of the Mail Alias Description.
33
 
    int numrecep;
 
33
    size_t desc_width; // The visual width of the Mail Alias Description.
34
34
    dbref list[MAX_MALIAS_MEMBERSHIP];
35
 
};
 
35
} malias_t;
36
36
 
37
37
static int ma_size = 0;
38
38
static int ma_top = 0;
39
39
 
40
 
static struct malias **malias   = NULL;
41
 
static MAILBODY      *mail_list = NULL;
 
40
static malias_t **malias   = NULL;
 
41
static MAILBODY *mail_list = NULL;
42
42
 
43
43
// Handling functions for the database of mail messages.
44
44
//
85
85
    for (int i = mudstate.mail_db_top; i < newtop; i++)
86
86
    {
87
87
        mail_list[i].m_nRefs = 0;
 
88
        mail_list[i].m_nMessage = 0;
88
89
        mail_list[i].m_pMessage = NULL;
89
90
    }
90
91
    mudstate.mail_db_top = newtop;
100
101
 
101
102
// MessageReferenceCheck - Checks whether the reference count for
102
103
// any particular message indicates that the message body should be
103
 
// freed. Also checks that if a message point is null, that the
 
104
// freed. Also checks that if a message pointer is null, that the
104
105
// reference count is zero.
105
106
//
106
107
static void MessageReferenceCheck(int number)
112
113
        {
113
114
            MEMFREE(m.m_pMessage);
114
115
            m.m_pMessage = NULL;
 
116
            m.m_nMessage = 0;
115
117
        }
116
118
    }
 
119
 
117
120
    if (m.m_pMessage == NULL)
118
121
    {
119
122
        m.m_nRefs = 0;
 
123
        m.m_nMessage = 0;
120
124
    }
121
125
}
122
126
 
132
136
// MessageFetch - returns the text for a particular message number. This
133
137
// text should not be modified.
134
138
//
135
 
static const char *MessageFetch(int number)
 
139
const char *MessageFetch(int number)
136
140
{
137
141
    MessageReferenceCheck(number);
138
142
    if (mail_list[number].m_pMessage)
145
149
    }
146
150
}
147
151
 
 
152
size_t MessageFetchSize(int number)
 
153
{
 
154
    MessageReferenceCheck(number);
 
155
    if (mail_list[number].m_pMessage)
 
156
    {
 
157
        return mail_list[number].m_nMessage;
 
158
    }
 
159
    else
 
160
    {
 
161
        return 0;
 
162
    }
 
163
}
 
164
 
148
165
// This function returns a reference to the message and the the
149
166
// reference count is increased to reflect that.
150
167
//
151
168
static int MessageAdd(char *pMessage)
152
169
{
153
 
    if (!mail_list)
154
 
    {
155
 
        mail_db_grow(1);
156
 
    }
157
 
 
158
170
    int i;
159
171
    MAILBODY *pm;
160
172
    bool bFound = false;
161
173
    for (i = 0; i < mudstate.mail_db_top; i++)
162
174
    {
163
175
        pm = &mail_list[i];
164
 
        if (pm->m_pMessage == NULL)
 
176
        if (NULL == pm->m_pMessage)
165
177
        {
166
178
            pm->m_nRefs = 0;
167
179
            bFound = true;
168
180
            break;
169
181
        }
170
182
    }
 
183
 
171
184
    if (!bFound)
172
185
    {
173
186
        mail_db_grow(i + 1);
174
187
    }
175
188
 
176
189
    pm = &mail_list[i];
177
 
    pm->m_pMessage = StringClone(pMessage);
 
190
    pm->m_nMessage = strlen(pMessage);
 
191
    pm->m_pMessage = StringCloneLen(pMessage, pm->m_nMessage);
178
192
    MessageReferenceInc(i);
179
193
    return i;
180
194
}
202
216
    char *execstr = bp;
203
217
    char *str = atrstr;
204
218
    mux_exec(execstr, &bp, player, player, player,
205
 
             EV_STRIP_CURLY | EV_FCHECK | EV_EVAL, &str, (char **)NULL, 0);
 
219
         AttrTrace(aflags, EV_STRIP_CURLY|EV_FCHECK|EV_EVAL), &str,
 
220
         NULL, 0);
206
221
    *bp = '\0';
207
222
 
208
223
    // Save message body and return a reference to it.
221
236
    mail_db_grow(i+1);
222
237
 
223
238
    MAILBODY *pm = &mail_list[i];
224
 
    pm->m_pMessage = StringClone(pMessage);
 
239
    pm->m_nMessage = strlen(pMessage);
 
240
    pm->m_pMessage = StringCloneLen(pMessage, pm->m_nMessage);
225
241
    return true;
226
242
}
227
243
 
299
315
    char *aNew = alloc_lbuf("add_folder_name.new");
300
316
    char *q = aNew;
301
317
    q += mux_ltoa(fld, q);
302
 
    *q++ = ':';
 
318
    safe_chr(':', aNew, &q);
303
319
    char *p = name;
304
320
    while (*p)
305
321
    {
306
 
        *q++ = mux_toupper(*p);
 
322
        safe_chr(mux_toupper(*p), aNew, &q);
307
323
        p++;
308
324
    }
309
 
    *q++ = ':';
 
325
    safe_chr(':', aNew, &q);
310
326
    q += mux_ltoa(fld, q);
311
327
    *q = '\0';
312
328
    size_t nNew = q - aNew;
318
334
        char *aPattern = alloc_lbuf("add_folder_name.pat");
319
335
        q = aPattern;
320
336
        q += mux_ltoa(fld, q);
321
 
        *q++ = ':';
 
337
        safe_chr(':', aPattern, &q);
322
338
        *q = '\0';
323
339
        size_t nPattern = q - aPattern;
324
340
 
326
342
        BMH_Prepare(&bmhs, nPattern, aPattern);
327
343
        for (;;)
328
344
        {
329
 
            int i = BMH_Execute(&bmhs, nPattern, aPattern, nFolders, aFolders);
330
 
            if (i < 0)
 
345
            size_t i;
 
346
            if (!BMH_Execute(&bmhs, &i, nPattern, aPattern, nFolders, aFolders))
331
347
            {
332
348
                break;
333
349
            }
368
384
            }
369
385
            while (*p)
370
386
            {
371
 
                *q++ = *p++;
 
387
                safe_chr(*p, aFolders, &q);
 
388
                p++;
372
389
            }
373
390
            *q = '\0';
374
391
            nFolders = q - aFolders;
415
432
        *p = '\0';
416
433
        size_t nPattern = p - aPattern;
417
434
 
418
 
        int i = BMH_StringSearch(nPattern, aPattern, nFolders, aFolders);
 
435
        size_t i;
 
436
        bool bSucceeded = BMH_StringSearch(&i, nPattern, aPattern, nFolders, aFolders);
419
437
        free_lbuf(aPattern);
420
438
 
421
 
        if (0 <= i)
 
439
        if (bSucceeded)
422
440
        {
423
441
            p = aFolders + i + nPattern;
424
442
            char *q = p;
431
449
            return p;
432
450
        }
433
451
    }
434
 
    p = "unnamed";
 
452
    p = (char *)"unnamed";
435
453
    return p;
436
454
}
437
455
 
449
467
    {
450
468
        char *aPattern = alloc_lbuf("get_folder_num_pat");
451
469
        char *q = aPattern;
452
 
        *q++ = ':';
 
470
        safe_chr(':', aPattern, &q);
453
471
        char *p = name;
454
472
        while (*p)
455
473
        {
456
 
            *q++ = mux_toupper(*p);
 
474
            safe_chr(mux_toupper(*p), aPattern, &q);
457
475
            p++;
458
476
        }
459
 
        *q++ = ':';
 
477
        safe_chr(':', aPattern, &q);
460
478
        *q = '\0';
461
479
        size_t nPattern = q - aPattern;
462
480
 
463
 
        int i = BMH_StringSearch(nPattern, aPattern, nFolders, aFolders);
 
481
        size_t i;
 
482
        bool bSucceeded = BMH_StringSearch(&i, nPattern, aPattern, nFolders, aFolders);
464
483
        free_lbuf(aPattern);
465
 
        if (0 <= i)
 
484
        if (bSucceeded)
466
485
        {
467
486
            p = aFolders + i + nPattern;
468
487
            q = p;
472
491
                q++;
473
492
            }
474
493
            *q = '\0';
475
 
            i = mux_atol(p);
 
494
 
 
495
            int iFolderNumber = mux_atol(p);
476
496
            free_lbuf(aFolders);
477
 
            return i;
 
497
            return iFolderNumber;
478
498
        }
479
499
    }
480
500
    free_lbuf(aFolders);
517
537
#define MAIL_INVALID_SPEC   5
518
538
#define MAIL_INVALID_PLAYER_OR_USING_MALIAS 6
519
539
 
520
 
static char *mailmsg[] =
 
540
static const char *mailmsg[] =
521
541
{
522
542
    "MAIL: Invalid message range",
523
543
    "MAIL: Invalid message number",
1158
1178
// letters, and digits. No leading digits. No symbols. No ANSI. Length is
1159
1179
// limited to SIZEOF_MALIAS-1. Case is preserved.
1160
1180
//
1161
 
static char *MakeCanonicalMailAlias
 
1181
char *MakeCanonicalMailAlias
1162
1182
(
1163
 
    char *pMailAlias,
1164
 
    int *pnValidMailAlias,
1165
 
    bool *pbValidMailAlias
 
1183
    char   *pMailAlias,
 
1184
    size_t *pnValidMailAlias,
 
1185
    bool   *pbValidMailAlias
1166
1186
)
1167
1187
{
1168
1188
    static char Buffer[SIZEOF_MALIAS];
1203
1223
#define GMA_FOUND       2
1204
1224
#define GMA_INVALIDFORM 3
1205
1225
 
1206
 
static struct malias *get_malias(dbref player, char *alias, int *pnResult)
 
1226
static malias_t *get_malias(dbref player, char *alias, int *pnResult)
1207
1227
{
1208
1228
    *pnResult = GMA_INVALIDFORM;
1209
1229
    if (!alias)
1226
1246
    }
1227
1247
    else if (alias[0] == '*')
1228
1248
    {
1229
 
        int  nValidMailAlias;
1230
 
        bool bValidMailAlias;
 
1249
        size_t nValidMailAlias;
 
1250
        bool   bValidMailAlias;
1231
1251
        char *pValidMailAlias = MakeCanonicalMailAlias
1232
1252
                                (   alias+1,
1233
1253
                                    &nValidMailAlias,
1238
1258
        {
1239
1259
            for (int i = 0; i < ma_top; i++)
1240
1260
            {
1241
 
                struct malias *m = malias[i];
 
1261
                malias_t *m = malias[i];
1242
1262
                if (  m->owner == player
1243
1263
                   || m->owner == GOD
1244
1264
                   || ExpMail(player))
1278
1298
    char *names = alloc_lbuf("make_namelist.names");
1279
1299
    char *bp = names;
1280
1300
 
1281
 
    strcpy(oldarg, arg);
 
1301
    mux_strncpy(oldarg, arg, LBUF_SIZE-1);
1282
1302
 
1283
1303
    MUX_STRTOK_STATE tts;
1284
1304
    mux_strtok_src(&tts, oldarg);
1309
1329
                {
1310
1330
                    safe_chr('!', names, &bp);
1311
1331
                }
1312
 
                safe_str(Name(target), names, &bp);
 
1332
                safe_str(Moniker(target), names, &bp);
1313
1333
            }
1314
1334
        }
1315
1335
        else
1326
1346
static struct tag_mailstatusentry
1327
1347
{
1328
1348
    int nMask;
1329
 
    char *pYes;
 
1349
    const char *pYes;
1330
1350
    int   nYes;
1331
 
    char *pNo;
 
1351
    const char *pNo;
1332
1352
    int   nNo;
1333
1353
}
1334
1354
aMailStatusTable[NUM_MAILSTATUSTABLE] =
1368
1388
    return tbuf1;
1369
1389
}
1370
1390
 
 
1391
 
 
1392
static void GetFromField(dbref target, char szFrom[MBUF_SIZE])
 
1393
{
 
1394
    size_t vw = 0;
 
1395
    size_t nFrom = ANSI_TruncateToField(Moniker(target), sizeof(szFrom)-16,
 
1396
        szFrom, 16, &vw, ANSI_ENDGOAL_NORMAL);
 
1397
 
 
1398
    while (  vw < 16
 
1399
          && nFrom < MBUF_SIZE)
 
1400
    {
 
1401
        szFrom[nFrom] = ' ';
 
1402
        nFrom++;
 
1403
        vw++;
 
1404
    }
 
1405
    szFrom[nFrom] = '\0';
 
1406
}
 
1407
 
 
1408
 
1371
1409
static void do_mail_read(dbref player, char *msglist)
1372
1410
{
1373
1411
    struct mail_selector ms;
1393
1431
                // Read it.
1394
1432
                //
1395
1433
                j++;
1396
 
                buff[LBUF_SIZE-1] = '\0';
1397
 
                strncpy(buff, MessageFetch(mp->number), LBUF_SIZE);
1398
 
                if (buff[LBUF_SIZE-1] != '\0')
1399
 
                {
1400
 
                    STARTLOG(LOG_BUGS, "BUG", "MAIL");
1401
 
                    log_text(tprintf("do_mail_read: %s: Mail message %d truncated.", Name(player), mp->number));
1402
 
                    ENDLOG;
1403
 
                    buff[LBUF_SIZE-1] = '\0';
1404
 
                }
 
1434
 
 
1435
                char *bp = buff;
 
1436
                safe_str(MessageFetch(mp->number), buff, &bp);
 
1437
                *bp = '\0';
 
1438
 
1405
1439
                notify(player, DASH_LINE);
1406
1440
                status = status_string(mp);
1407
1441
                names = make_namelist(player, mp->tolist);
 
1442
 
 
1443
                char szFromName[MBUF_SIZE];
 
1444
                GetFromField(mp->from, szFromName);
 
1445
 
1408
1446
                char szSubjectBuffer[MBUF_SIZE];
1409
 
                int iRealVisibleWidth;
 
1447
                size_t iRealVisibleWidth;
1410
1448
                ANSI_TruncateToField(mp->subject, sizeof(szSubjectBuffer),
1411
1449
                    szSubjectBuffer, 65, &iRealVisibleWidth, ANSI_ENDGOAL_NORMAL);
1412
 
                notify(player, tprintf("%-3d         From:  %-*s  At: %-25s  %s\r\nFldr   : %-2d Status: %s\r\nTo     : %-65s\r\nSubject: %s",
1413
 
                               i, PLAYER_NAME_LIMIT - 6, Name(mp->from),
 
1450
 
 
1451
                notify(player, tprintf("%-3d         From:  %s  At: %-25s  %s\r\nFldr   : %-2d Status: %s\r\nTo     : %-65s\r\nSubject: %s",
 
1452
                               i, szFromName,
1414
1453
                               mp->time,
1415
1454
                               (Connected(mp->from) &&
1416
1455
                               (!Hidden(mp->from) || See_Hidden(player))) ?
1472
1511
    struct mail *mp;
1473
1512
    struct mail_selector ms;
1474
1513
    int i = 0, j = 0;
1475
 
    int iRealVisibleWidth;
 
1514
    size_t iRealVisibleWidth;
1476
1515
    char szSubjectBuffer[MBUF_SIZE];
1477
1516
 
1478
1517
    if (  !msglist
1479
1518
       || !*msglist)
1480
1519
    {
1481
 
        notify(player, tprintf("--------------------   MAIL: %-25s   ------------------", Name(target)));
 
1520
        notify(player, tprintf("--------------------   MAIL: %-25s   ------------------", Moniker(target)));
1482
1521
        MailList ml(target);
1483
1522
        for (mp = ml.FirstItem(); !ml.IsEnd(); mp = ml.NextItem())
1484
1523
        {
1485
1524
            if (mp->from == player)
1486
1525
            {
1487
1526
                i++;
 
1527
 
 
1528
                char szFromName[MBUF_SIZE];
 
1529
                GetFromField(mp->from, szFromName);
 
1530
 
1488
1531
                ANSI_TruncateToField(mp->subject, sizeof(szSubjectBuffer),
1489
1532
                    szSubjectBuffer, 25, &iRealVisibleWidth, ANSI_ENDGOAL_NORMAL);
1490
 
                size_t nSize = strlen(MessageFetch(mp->number));
1491
 
                const char *pFromName = Name(mp->from);
1492
 
                notify(player, tprintf("[%s] %-3d (%4d) From: %-*s Sub: %s",
 
1533
                size_t nSize = MessageFetchSize(mp->number);
 
1534
                notify(player, tprintf("[%s] %-3d (%4d) From: %s Sub: %s",
1493
1535
                               status_chars(mp),
1494
1536
                               i, nSize,
1495
 
                               PLAYER_NAME_LIMIT - 6, pFromName,
 
1537
                               szFromName,
1496
1538
                               szSubjectBuffer));
1497
1539
            }
1498
1540
        }
1515
1557
                    j++;
1516
1558
                    char *status = status_string(mp);
1517
1559
                    const char *str = MessageFetch(mp->number);
 
1560
 
 
1561
                    char szFromName[MBUF_SIZE];
 
1562
                    GetFromField(mp->from, szFromName);
 
1563
 
1518
1564
                    ANSI_TruncateToField(mp->subject, sizeof(szSubjectBuffer),
1519
1565
                        szSubjectBuffer, 65, &iRealVisibleWidth, ANSI_ENDGOAL_NORMAL);
 
1566
 
1520
1567
                    notify(player, DASH_LINE);
1521
 
                    notify(player, tprintf("%-3d         From:  %-*s  At: %-25s  %s\r\nFldr   : %-2d Status: %s\r\nSubject: %s",
1522
 
                                   i, PLAYER_NAME_LIMIT - 6, Name(mp->from),
 
1568
                    notify(player, tprintf("%-3d         From:  %s  At: %-25s  %s\r\nFldr   : %-2d Status: %s\r\nSubject: %s",
 
1569
                                   i, szFromName,
1523
1570
                                   mp->time,
1524
1571
                                   (Connected(mp->from) &&
1525
1572
                                   (!Hidden(mp->from) || See_Hidden(player))) ?
1595
1642
    }
1596
1643
    int i = 0;
1597
1644
    char *time;
1598
 
    int iRealVisibleWidth;
 
1645
    size_t iRealVisibleWidth;
1599
1646
    char szSubjectBuffer[MBUF_SIZE];
1600
1647
    int folder = player_folder(player);
1601
1648
 
1612
1659
            if (mail_match(mp, ms, i))
1613
1660
            {
1614
1661
                time = mail_list_time(mp->time);
1615
 
                size_t nSize = strlen(MessageFetch(mp->number));
1616
 
                const char *pFromName = Name(mp->from);
 
1662
                size_t nSize = MessageFetchSize(mp->number);
 
1663
 
 
1664
                char szFromName[MBUF_SIZE];
 
1665
                GetFromField(mp->from, szFromName);
 
1666
 
1617
1667
                if (sub)
1618
1668
                {
1619
1669
                    ANSI_TruncateToField(mp->subject, sizeof(szSubjectBuffer),
1620
1670
                        szSubjectBuffer, 25, &iRealVisibleWidth, ANSI_ENDGOAL_NORMAL);
1621
1671
 
1622
 
                    notify(player, tprintf("[%s] %-3d (%4d) From: %-*s Sub: %s",
1623
 
                        status_chars(mp), i, nSize, PLAYER_NAME_LIMIT - 6, pFromName, szSubjectBuffer));
 
1672
                    notify(player, tprintf("[%s] %-3d (%4d) From: %s Sub: %s",
 
1673
                        status_chars(mp), i, nSize, szFromName, szSubjectBuffer));
1624
1674
                }
1625
1675
                else
1626
1676
                {
1627
 
                    notify(player, tprintf("[%s] %-3d (%4d) From: %-*s At: %s %s",
1628
 
                        status_chars(mp), i, nSize, PLAYER_NAME_LIMIT - 6, pFromName, time,
 
1677
                    notify(player, tprintf("[%s] %-3d (%4d) From: %s At: %s %s",
 
1678
                        status_chars(mp), i, nSize, szFromName, time,
1629
1679
                            ((Connected(mp->from) && (!Hidden(mp->from) || See_Hidden(player))) ? "Conn" : " ")));
1630
1680
                }
1631
1681
                free_lbuf(time);
1654
1704
static char *make_numlist(dbref player, char *arg, bool bBlind)
1655
1705
{
1656
1706
    char *tail, spot;
1657
 
    struct malias *m;
 
1707
    malias_t *m;
1658
1708
    dbref target;
1659
1709
    int nRecip = 0;
1660
1710
    dbref aRecip[(LBUF_SIZE+1)/2];
1848
1898
        notify(player, "MAIL: You can't forward non-existent messages.");
1849
1899
        return;
1850
1900
    }
1851
 
    do_expmail_start(player, tolist, tprintf("%s (fwd from %s)", mp->subject, Name(mp->from)));
 
1901
    do_expmail_start(player, tolist, tprintf("%s (fwd from %s)", mp->subject, Moniker(mp->from)));
1852
1902
    atr_add_raw(player, A_MAILMSG, MessageFetch(mp->number));
1853
1903
    const char *pValue = atr_get_raw(player, A_MAILFLAGS);
1854
1904
    int iFlag = M_FORWARD;
1898
1948
        bp = names;
1899
1949
        *bp = '\0';
1900
1950
 
1901
 
        strcpy(oldlist, mp->tolist);
 
1951
        mux_strncpy(oldlist, mp->tolist, LBUF_SIZE-1);
1902
1952
 
1903
1953
        MUX_STRTOK_STATE tts;
1904
1954
        mux_strtok_src(&tts, oldlist);
1917
1967
        safe_chr('#', names, &bp);
1918
1968
        safe_ltoa(mp->from, names, &bp);
1919
1969
        *bp = '\0';
1920
 
        strcpy(tolist, names);
 
1970
        mux_strncpy(tolist, names, LBUF_SIZE-1);
1921
1971
        free_lbuf(names);
1922
1972
    }
1923
1973
    else
1940
1990
    }
1941
1991
    if (key & MAIL_QUOTE)
1942
1992
    {
1943
 
        const char *pFromName = Name(mp->from);
 
1993
        const char *pFromName = Moniker(mp->from);
1944
1994
        char *pMessageBody =
1945
1995
            tprintf("On %s, %s wrote:\r\n\r\n%s\r\n\r\n********** End of included message from %s\r\n",
1946
1996
                pTime, pFromName, pMessage, pFromName);
2077
2127
        str2 = bp = alloc_lbuf("mail_return");
2078
2128
        buf = str;
2079
2129
        mux_exec(str2, &bp, target, player, player,
2080
 
                 EV_FCHECK | EV_EVAL | EV_TOP | EV_NO_LOCATION, &buf,
2081
 
                 (char **)NULL, 0);
 
2130
             AttrTrace(aflags, EV_FCHECK|EV_EVAL|EV_TOP|EV_NO_LOCATION), &buf,
 
2131
             NULL, 0);
2082
2132
        *bp = '\0';
2083
2133
        if (*str2)
2084
2134
        {
2154
2204
 
2155
2205
    // Initialize the appropriate fields.
2156
2206
    //
2157
 
    struct mail *newp = (struct mail *)MEMALLOC(sizeof(struct mail));
2158
 
    ISOUTOFMEMORY(newp);
 
2207
    struct mail *newp = NULL;
 
2208
    try
 
2209
    {
 
2210
        newp = new struct mail;
 
2211
    }
 
2212
    catch (...)
 
2213
    {
 
2214
        ; // Nothing.
 
2215
    }
 
2216
 
 
2217
    if (NULL == newp)
 
2218
    {
 
2219
        notify(player, "MAIL: Out of memory.");
 
2220
        return;
 
2221
    }
 
2222
 
2159
2223
    newp->to = target;
2160
2224
 
2161
2225
    // HACK: Allow @mail/quick, if player is an object, then the
2206
2270
    //
2207
2271
    if (!silent)
2208
2272
    {
2209
 
        notify(player, tprintf("MAIL: You sent your message to %s.", Name(target)));
 
2273
        notify(player, tprintf("MAIL: You sent your message to %s.", Moniker(target)));
2210
2274
    }
2211
2275
 
2212
 
    notify(target, tprintf("MAIL: You have a new message from %s.", Name(player)));
2213
 
    did_it(player, target, A_MAIL, NULL, 0, NULL, A_AMAIL, NULL, NOTHING);
 
2276
    notify(target, tprintf("MAIL: You have a new message from %s.", Moniker(player)));
 
2277
    did_it(player, target, A_MAIL, NULL, 0, NULL, A_AMAIL, 0, NULL, NOTHING);
2214
2278
}
2215
2279
 
2216
2280
static void do_mail_nuke(dbref player)
2229
2293
        MailList ml(thing);
2230
2294
        ml.RemoveAll();
2231
2295
    }
2232
 
    log_text(tprintf("** MAIL PURGE ** done by %s(#%d)." ENDLINE, Name(player), player));
 
2296
    log_text(tprintf("** MAIL PURGE ** done by %s(#%d)." ENDLINE, Moniker(player), player));
2233
2297
    notify(player, "You annihilate the post office. All messages cleared.");
2234
2298
}
2235
2299
 
2258
2322
        }
2259
2323
        if (Wizard(target))
2260
2324
        {
2261
 
            notify(player, tprintf("Let %s clear their own @mail.", Name(target)));
 
2325
            notify(player, tprintf("Let %s clear their own @mail.", Moniker(target)));
2262
2326
            return;
2263
2327
        }
2264
2328
        do_mail_clear(target, NULL);
2265
2329
        do_mail_purge(target);
2266
 
        notify(player, tprintf("Mail cleared for %s(#%d).", Name(target), target));
 
2330
        notify(player, tprintf("Mail cleared for %s(#%d).", Moniker(target), target));
2267
2331
        return;
2268
2332
    }
2269
2333
    else if (string_prefix("sanity", action))
2270
2334
    {
2271
 
        int *ai = (int *)MEMALLOC(mudstate.mail_db_top * sizeof(int));
2272
 
        ISOUTOFMEMORY(ai);
 
2335
        int *ai = NULL;
 
2336
        try
 
2337
        {
 
2338
            ai = new int[mudstate.mail_db_top];
 
2339
        }
 
2340
        catch (...)
 
2341
        {
 
2342
            ; // Nothing.
 
2343
        }
 
2344
 
 
2345
        if (NULL == ai)
 
2346
        {
 
2347
            notify(player, "Out of memory.");
 
2348
            return;
 
2349
        }
 
2350
 
2273
2351
        memset(ai, 0, mudstate.mail_db_top * sizeof(int));
2274
2352
 
2275
2353
        DO_WHOLE_DB(thing)
2304
2382
                    if (bGoodReference)
2305
2383
                    {
2306
2384
                        notify(player, tprintf("%s(#%d) has mail, but is not a player.",
2307
 
                                 Name(mp->to), mp->to));
 
2385
                                 Moniker(mp->to), mp->to));
2308
2386
                    }
2309
2387
                    else
2310
2388
                    {
2311
2389
                        notify(player, tprintf("%s(#%d) is not a player, but has mail which refers to a non-existent mailbag item.",
2312
 
                             Name(mp->to), mp->to));
 
2390
                             Moniker(mp->to), mp->to));
2313
2391
                    }
2314
2392
                }
2315
2393
                else if (!bGoodReference)
2316
2394
                {
2317
 
                    notify(player, tprintf("%s(#%d) has mail which refers to a non-existent mailbag item.", Name(mp->to), mp->to));
 
2395
                    notify(player, tprintf("%s(#%d) has mail which refers to a non-existent mailbag item.", Moniker(mp->to), mp->to));
2318
2396
                }
2319
2397
            }
2320
2398
        }
2346
2424
                notify(player, "Some mailbag items are referred to less often than the mailbag item indicates.");
2347
2425
            }
2348
2426
        }
2349
 
        MEMFREE(ai);
 
2427
 
 
2428
        delete [] ai;
2350
2429
        ai = NULL;
2351
2430
        notify(player, "Mail sanity check completed.");
2352
2431
    }
2357
2436
        if (mail_list)
2358
2437
        {
2359
2438
            notify(player, tprintf("Re-counting mailbag reference counts."));
2360
 
            int *ai = (int *)MEMALLOC(mudstate.mail_db_top * sizeof(int));
2361
 
            ISOUTOFMEMORY(ai);
 
2439
            int *ai = NULL;
 
2440
            try
 
2441
            {
 
2442
                ai = new int[mudstate.mail_db_top];
 
2443
            }
 
2444
            catch (...)
 
2445
            {
 
2446
                ; // Nothing.
 
2447
            }
 
2448
 
 
2449
            if (NULL == ai)
 
2450
            {
 
2451
                notify(player, "Out of memory.");
 
2452
                return;
 
2453
            }
 
2454
 
2362
2455
            memset(ai, 0, mudstate.mail_db_top * sizeof(int));
2363
2456
 
2364
2457
            DO_WHOLE_DB(thing)
2392
2485
            {
2393
2486
                notify(player, "Some reference counts were wrong [FIXED].");
2394
2487
            }
2395
 
            MEMFREE(ai);
 
2488
 
 
2489
            delete [] ai;
2396
2490
            ai = NULL;
2397
2491
        }
2398
2492
 
2430
2524
static void do_mail_stats(dbref player, char *name, int full)
2431
2525
{
2432
2526
    dbref target, thing;
2433
 
    int fc, fr, fu, tc, tr, tu, fchars, tchars, cchars, count;
2434
 
    fc = fr = fu = tc = tr = tu = fchars = tchars = cchars = count = 0;
 
2527
    int fc, fr, fu, tc, tr, tu, count;
 
2528
    size_t cchars = 0;
 
2529
    size_t fchars = 0;
 
2530
    size_t tchars = 0;
 
2531
    fc = fr = fu = tc = tr = tu = count = 0;
2435
2532
 
2436
2533
    // Find player.
2437
2534
    //
2545
2642
                    if (Cleared(mp))
2546
2643
                    {
2547
2644
                        fc++;
2548
 
                        cchars += strlen(MessageFetch(mp->number));
 
2645
                        cchars += MessageFetchSize(mp->number) + 1;
2549
2646
                    }
2550
2647
                    else if (Read(mp))
2551
2648
                    {
2552
2649
                        fr++;
2553
 
                        fchars += strlen(MessageFetch(mp->number));
 
2650
                        fchars += MessageFetchSize(mp->number) + 1;
2554
2651
                    }
2555
2652
                    else
2556
2653
                    {
2557
2654
                        fu++;
2558
 
                        tchars += strlen(MessageFetch(mp->number));
 
2655
                        tchars += MessageFetchSize(mp->number) + 1;
2559
2656
                    }
2560
2657
                }
2561
2658
            }
2588
2685
                }
2589
2686
            }
2590
2687
        }
2591
 
        notify(player, tprintf("%s sent %d messages.", Name(target), fr));
2592
 
        notify(player, tprintf("%s has %d messages.", Name(target), tr));
 
2688
        notify(player, tprintf("%s sent %d messages.", Moniker(target), fr));
 
2689
        notify(player, tprintf("%s has %d messages.", Moniker(target), tr));
2593
2690
        return;
2594
2691
    }
2595
2692
 
2618
2715
                }
2619
2716
                if (full == 2)
2620
2717
                {
2621
 
                    fchars += strlen(MessageFetch(mp->number));
 
2718
                    fchars += MessageFetchSize(mp->number) + 1;
2622
2719
                }
2623
2720
            }
2624
2721
            if (mp->to == target)
2625
2722
            {
2626
2723
                if (!tr && !tu)
2627
2724
                {
2628
 
                    strcpy(last, mp->time);
 
2725
                    mux_strncpy(last, mp->time, 49);
2629
2726
                }
2630
2727
                if (Cleared(mp))
2631
2728
                {
2641
2738
                }
2642
2739
                if (full == 2)
2643
2740
                {
2644
 
                    tchars += strlen(MessageFetch(mp->number));
 
2741
                    tchars += MessageFetchSize(mp->number) + 1;
2645
2742
                }
2646
2743
            }
2647
2744
        }
2648
2745
    }
2649
2746
 
2650
 
    notify(player, tprintf("Mail statistics for %s:", Name(target)));
 
2747
    notify(player, tprintf("Mail statistics for %s:", Moniker(target)));
2651
2748
 
2652
2749
    if (full == 1)
2653
2750
    {
2739
2836
static void malias_write(FILE *fp)
2740
2837
{
2741
2838
    int i, j;
2742
 
    struct malias *m;
 
2839
    malias_t *m;
2743
2840
 
2744
2841
    putref(fp, ma_top);
2745
2842
    for (i = 0; i < ma_top; i++)
2808
2905
    return count;
2809
2906
}
2810
2907
 
 
2908
static void load_mail_V6(FILE *fp)
 
2909
{
 
2910
    int mail_top = getref(fp);
 
2911
    mail_db_grow(mail_top + 1);
 
2912
 
 
2913
    size_t nBuffer;
 
2914
    char *pBuffer;
 
2915
 
 
2916
    char nbuf1[8];
 
2917
    char *p = fgets(nbuf1, sizeof(nbuf1), fp);
 
2918
    while (  p
 
2919
          && strncmp(nbuf1, "***", 3) != 0)
 
2920
    {
 
2921
        struct mail *mp = NULL;
 
2922
        try
 
2923
        {
 
2924
            mp = new struct mail;
 
2925
        }
 
2926
        catch (...)
 
2927
        {
 
2928
            ; // Nothing.
 
2929
        }
 
2930
 
 
2931
        if (NULL == mp)
 
2932
        {
 
2933
            STARTLOG(LOG_BUGS, "BUG", "MAIL");
 
2934
            log_text("Out of memory.");
 
2935
            ENDLOG;
 
2936
            return;
 
2937
        }
 
2938
 
 
2939
        mp->to      = mux_atol(nbuf1);
 
2940
        mp->from    = getref(fp);
 
2941
 
 
2942
        mp->number  = getref(fp);
 
2943
        MessageReferenceInc(mp->number);
 
2944
 
 
2945
        pBuffer = getstring_noalloc(fp, true, &nBuffer);
 
2946
        pBuffer = (char *)convert_color((UTF8 *)pBuffer);
 
2947
        pBuffer = ConvertToLatin((UTF8 *)pBuffer);
 
2948
        nBuffer = strlen(pBuffer);
 
2949
        mp->tolist = StringCloneLen(pBuffer, nBuffer);
 
2950
 
 
2951
        pBuffer = getstring_noalloc(fp, true, &nBuffer);
 
2952
        pBuffer = (char *)convert_color((UTF8 *)pBuffer);
 
2953
        pBuffer = ConvertToLatin((UTF8 *)pBuffer);
 
2954
        nBuffer = strlen(pBuffer);
 
2955
        mp->time = StringCloneLen(pBuffer, nBuffer);
 
2956
 
 
2957
        pBuffer = getstring_noalloc(fp, true, &nBuffer);
 
2958
        pBuffer = (char *)convert_color((UTF8 *)pBuffer);
 
2959
        pBuffer = ConvertToLatin((UTF8 *)pBuffer);
 
2960
        nBuffer = strlen(pBuffer);
 
2961
        mp->subject = StringCloneLen(pBuffer, nBuffer);
 
2962
 
 
2963
        mp->read    = getref(fp);
 
2964
 
 
2965
        MailList ml(mp->to);
 
2966
        ml.AppendItem(mp);
 
2967
 
 
2968
        p = fgets(nbuf1, sizeof(nbuf1), fp);
 
2969
    }
 
2970
 
 
2971
    p = fgets(nbuf1, sizeof(nbuf1), fp);
 
2972
    while (  p
 
2973
          && strncmp(nbuf1, "+++", 3))
 
2974
    {
 
2975
        int number = mux_atol(nbuf1);
 
2976
        pBuffer = getstring_noalloc(fp, true, &nBuffer);
 
2977
        pBuffer = (char *)convert_color((UTF8 *)pBuffer);
 
2978
        pBuffer = ConvertToLatin((UTF8 *)pBuffer);
 
2979
        nBuffer = strlen(pBuffer);
 
2980
        new_mail_message(pBuffer, number);
 
2981
        p = fgets(nbuf1, sizeof(nbuf1), fp);
 
2982
    }
 
2983
}
 
2984
 
2811
2985
static void load_mail_V5(FILE *fp)
2812
2986
{
2813
2987
    int mail_top = getref(fp);
2814
2988
    mail_db_grow(mail_top + 1);
2815
2989
 
 
2990
    size_t nBuffer;
 
2991
    char  *pBuffer;
2816
2992
    char nbuf1[8];
2817
2993
    char *p = fgets(nbuf1, sizeof(nbuf1), fp);
2818
 
    while (p && strncmp(nbuf1, "***", 3) != 0)
 
2994
    while (  p
 
2995
          && strncmp(nbuf1, "***", 3) != 0)
2819
2996
    {
2820
 
        struct mail *mp = (struct mail *)MEMALLOC(sizeof(struct mail));
2821
 
        ISOUTOFMEMORY(mp);
 
2997
        struct mail *mp = NULL;
 
2998
        try
 
2999
        {
 
3000
            mp = new struct mail;
 
3001
        }
 
3002
        catch (...)
 
3003
        {
 
3004
            ; // Nothing.
 
3005
        }
 
3006
 
 
3007
        if (NULL == mp)
 
3008
        {
 
3009
            STARTLOG(LOG_BUGS, "BUG", "MAIL");
 
3010
            log_text("Out of memory.");
 
3011
            ENDLOG;
 
3012
            return;
 
3013
        }
2822
3014
 
2823
3015
        mp->to      = mux_atol(nbuf1);
2824
3016
        mp->from    = getref(fp);
2825
3017
 
2826
3018
        mp->number  = getref(fp);
2827
3019
        MessageReferenceInc(mp->number);
2828
 
        mp->tolist  = StringClone(getstring_noalloc(fp, true));
2829
 
 
2830
 
        mp->time    = StringClone(getstring_noalloc(fp, true));
2831
 
        mp->subject = StringClone(getstring_noalloc(fp, true));
 
3020
        pBuffer = getstring_noalloc(fp, true, &nBuffer);
 
3021
        mp->tolist  = StringCloneLen(pBuffer, nBuffer);
 
3022
        pBuffer = getstring_noalloc(fp, true, &nBuffer);
 
3023
        mp->time    = StringCloneLen(pBuffer, nBuffer);
 
3024
        pBuffer = getstring_noalloc(fp, true, &nBuffer);
 
3025
        mp->subject = StringCloneLen(pBuffer, nBuffer);
2832
3026
        mp->read    = getref(fp);
2833
3027
 
2834
3028
        MailList ml(mp->to);
2841
3035
    while (p && strncmp(nbuf1, "+++", 3))
2842
3036
    {
2843
3037
        int number = mux_atol(nbuf1);
2844
 
        new_mail_message(getstring_noalloc(fp, true), number);
 
3038
        pBuffer = getstring_noalloc(fp, true, &nBuffer);
 
3039
        new_mail_message(pBuffer, number);
2845
3040
        p = fgets(nbuf1, sizeof(nbuf1), fp);
2846
3041
    }
2847
3042
}
2851
3046
// Length is limited to SIZEOF_MALIASDESC-1. Visual width is limited to
2852
3047
// WIDTHOF_MALIASDESC. Case is preserved.
2853
3048
//
2854
 
static char *MakeCanonicalMailAliasDesc
 
3049
char *MakeCanonicalMailAliasDesc
2855
3050
(
2856
 
    char *pMailAliasDesc,
2857
 
    int *pnValidMailAliasDesc,
2858
 
    bool *pbValidMailAliasDesc,
2859
 
    int *pnVisualWidth
 
3051
    char   *pMailAliasDesc,
 
3052
    size_t *pnValidMailAliasDesc,
 
3053
    bool   *pbValidMailAliasDesc,
 
3054
    size_t *pnVisualWidth
2860
3055
)
2861
3056
{
2862
3057
    if (!pMailAliasDesc)
2884
3079
    return szFittedMailAliasDesc;
2885
3080
}
2886
3081
 
2887
 
static void malias_read(FILE *fp)
 
3082
static void malias_read(FILE *fp, bool bConvert)
2888
3083
{
2889
3084
    int i, j;
2890
3085
 
2894
3089
        return;
2895
3090
    }
2896
3091
    char buffer[LBUF_SIZE];
2897
 
    struct malias *m;
2898
3092
 
2899
3093
    ma_size = ma_top = i;
2900
3094
 
2901
 
    malias = (struct malias **)MEMALLOC(sizeof(struct malias *) * ma_size);
2902
 
    ISOUTOFMEMORY(malias);
 
3095
    malias = NULL;
 
3096
    try
 
3097
    {
 
3098
        malias = new malias_t *[ma_size];
 
3099
    }
 
3100
    catch (...)
 
3101
    {
 
3102
        ; // Nothing.
 
3103
    }
 
3104
 
 
3105
    if (NULL == malias)
 
3106
    {
 
3107
        STARTLOG(LOG_BUGS, "BUG", "MAIL");
 
3108
        log_text("Out of memory.");
 
3109
        ENDLOG;
 
3110
        return;
 
3111
    }
2903
3112
 
2904
3113
    for (i = 0; i < ma_top; i++)
2905
3114
    {
2910
3119
            // We've hit the end of the file. Set the last recognized
2911
3120
            // @malias, and give up.
2912
3121
            //
2913
 
            ma_top = i;
2914
 
            return;
2915
 
        }
2916
 
 
2917
 
        m = (struct malias *)MEMALLOC(sizeof(struct malias));
2918
 
        ISOUTOFMEMORY(m);
 
3122
            STARTLOG(LOG_BUGS, "BUG", "MAIL");
 
3123
            log_text("Unexpected end of file. Mail bag truncated.");
 
3124
            ENDLOG;
 
3125
 
 
3126
            ma_top = i;
 
3127
            return;
 
3128
        }
 
3129
 
 
3130
        malias_t *m = NULL;
 
3131
        try
 
3132
        {
 
3133
            m = new malias_t;
 
3134
        }
 
3135
        catch (...)
 
3136
        {
 
3137
            ; // Nothing.
 
3138
        }
 
3139
 
 
3140
        if (NULL == m)
 
3141
        {
 
3142
            STARTLOG(LOG_BUGS, "BUG", "MAIL");
 
3143
            log_text("Out of memory. Mail bag truncated.");
 
3144
            ENDLOG;
 
3145
 
 
3146
            ma_top = i;
 
3147
            return;
 
3148
        }
 
3149
 
2919
3150
        malias[i] = m;
2920
3151
 
2921
3152
        char *p = strchr(buffer, ' ');
2928
3159
 
2929
3160
        // The format of @malias name is "N:<name>\n".
2930
3161
        //
2931
 
        int nLen = GetLineTrunc(buffer, sizeof(buffer), fp);
 
3162
        size_t nLen = GetLineTrunc(buffer, sizeof(buffer), fp);
2932
3163
        buffer[nLen-1] = '\0'; // Get rid of trailing '\n'.
2933
 
        int  nMailAlias;
 
3164
 
 
3165
        char *pBuffer = buffer;
 
3166
        if (bConvert)
 
3167
        {
 
3168
            pBuffer = (char *)convert_color((UTF8 *)pBuffer);
 
3169
            pBuffer = ConvertToLatin((UTF8 *)pBuffer);
 
3170
        }
 
3171
 
 
3172
        size_t nMailAlias;
2934
3173
        bool bMailAlias;
2935
 
        char *pMailAlias = MakeCanonicalMailAlias( buffer+2,
 
3174
        char *pMailAlias = MakeCanonicalMailAlias( pBuffer+2,
2936
3175
                                                   &nMailAlias,
2937
3176
                                                   &bMailAlias);
2938
3177
        if (bMailAlias)
2947
3186
        // The format of the description is "D:<description>\n"
2948
3187
        //
2949
3188
        nLen = GetLineTrunc(buffer, sizeof(buffer), fp);
2950
 
        int  nMailAliasDesc;
 
3189
 
 
3190
        pBuffer = buffer;
 
3191
        if (bConvert)
 
3192
        {
 
3193
            pBuffer = (char *)convert_color((UTF8 *)pBuffer);
 
3194
            pBuffer = ConvertToLatin((UTF8 *)pBuffer);
 
3195
        }
 
3196
 
 
3197
        size_t  nMailAliasDesc;
2951
3198
        bool bMailAliasDesc;
2952
 
        int  nVisualWidth;
2953
 
        char *pMailAliasDesc = MakeCanonicalMailAliasDesc( buffer+2,
 
3199
        size_t nVisualWidth;
 
3200
        char *pMailAliasDesc = MakeCanonicalMailAliasDesc( pBuffer+2,
2954
3201
                                                           &nMailAliasDesc,
2955
3202
                                                           &bMailAliasDesc,
2956
3203
                                                           &nVisualWidth);
2983
3230
    }
2984
3231
}
2985
3232
 
2986
 
static void load_malias(FILE *fp)
 
3233
static void load_malias(FILE *fp, bool bConvert)
2987
3234
{
2988
3235
    char buffer[200];
2989
3236
 
2990
3237
    getref(fp);
2991
 
    if (  fscanf(fp, "*** Begin %s ***\n", buffer) == 1
2992
 
       && !strcmp(buffer, "MALIAS"))
 
3238
    if (  fgets(buffer, sizeof(buffer), fp)
 
3239
       && strcmp(buffer, "*** Begin MALIAS ***\n") == 0)
2993
3240
    {
2994
 
        malias_read(fp);
 
3241
        malias_read(fp, bConvert);
2995
3242
    }
2996
3243
    else
2997
3244
    {
3010
3257
    {
3011
3258
        return;
3012
3259
    }
 
3260
 
 
3261
    bool bConvert = false;
3013
3262
    if (strncmp(nbuf1, "+V5", 3) == 0)
3014
3263
    {
3015
3264
        load_mail_V5(fp);
3016
3265
    }
 
3266
    else if (strncmp(nbuf1, "+V6", 3) == 0)
 
3267
    {
 
3268
        // Started v6 on 2007-MAR-13.
 
3269
        //
 
3270
        load_mail_V6(fp);
 
3271
        bConvert = true;
 
3272
    }
3017
3273
    else
3018
3274
    {
3019
3275
        return;
3020
3276
    }
3021
 
    load_malias(fp);
 
3277
    load_malias(fp, bConvert);
3022
3278
}
3023
3279
 
3024
3280
void check_mail_expiration(void)
3112
3368
)
3113
3369
{
3114
3370
    int nResult;
3115
 
    struct malias *m = get_malias(player, tolist, &nResult);
 
3371
    malias_t *m = get_malias(player, tolist, &nResult);
3116
3372
    if (nResult == GMA_INVALIDFORM)
3117
3373
    {
3118
3374
        notify(player, tprintf("MAIL: I can't figure out from '%s' who you want to mail to.", tolist));
3153
3409
 
3154
3410
static void do_malias_create(dbref player, char *alias, char *tolist)
3155
3411
{
3156
 
    struct malias **nm;
 
3412
    malias_t **nm;
3157
3413
    int nResult;
3158
3414
    get_malias(player, alias, &nResult);
3159
3415
 
3168
3424
        return;
3169
3425
    }
3170
3426
 
 
3427
    malias_t *pt = NULL;
 
3428
    try
 
3429
    {
 
3430
        pt = new malias_t;
 
3431
    }
 
3432
    catch (...)
 
3433
    {
 
3434
        ; // Nothing.
 
3435
    }
 
3436
 
 
3437
    if (NULL == pt)
 
3438
    {
 
3439
        notify(player, "MAIL: Out of memory.");
 
3440
        return;
 
3441
    }
 
3442
 
3171
3443
    int i = 0;
3172
3444
    if (!ma_size)
3173
3445
    {
3174
3446
        ma_size = MA_INC;
3175
 
        malias = (struct malias **)MEMALLOC(sizeof(struct malias *) * ma_size);
3176
 
        ISOUTOFMEMORY(malias);
 
3447
        malias = NULL;
 
3448
        try
 
3449
        {
 
3450
            malias = new malias_t *[ma_size];
 
3451
        }
 
3452
        catch (...)
 
3453
        {
 
3454
            ; // Nothing.
 
3455
        }
 
3456
 
 
3457
        if (NULL == malias)
 
3458
        {
 
3459
            notify(player, "MAIL: Out of memory.");
 
3460
            delete pt;
 
3461
            return;
 
3462
        }
3177
3463
    }
3178
3464
    else if (ma_top >= ma_size)
3179
3465
    {
3180
3466
        ma_size += MA_INC;
3181
 
        nm = (struct malias **)MEMALLOC(sizeof(struct malias *) * (ma_size));
3182
 
        ISOUTOFMEMORY(nm);
 
3467
        nm = NULL;
 
3468
        try
 
3469
        {
 
3470
            nm = new malias_t *[ma_size];
 
3471
        }
 
3472
        catch (...)
 
3473
        {
 
3474
            ; // Nothing.
 
3475
        }
 
3476
 
 
3477
        if (NULL == nm)
 
3478
        {
 
3479
            notify(player, "MAIL: Out of memory.");
 
3480
            delete pt;
 
3481
            return;
 
3482
        }
3183
3483
 
3184
3484
        for (i = 0; i < ma_top; i++)
3185
3485
        {
3186
3486
            nm[i] = malias[i];
3187
3487
        }
3188
 
        MEMFREE(malias);
 
3488
 
 
3489
        delete [] malias;
3189
3490
        malias = nm;
3190
3491
    }
3191
 
    malias[ma_top] = (struct malias *)MEMALLOC(sizeof(struct malias));
3192
 
    ISOUTOFMEMORY(malias[ma_top]);
3193
3492
 
 
3493
    malias[ma_top] = pt;
3194
3494
 
3195
3495
    // Parse the player list.
3196
3496
    //
3272
3572
            head++;
3273
3573
        }
3274
3574
    }
3275
 
    int  nValidMailAlias;
3276
 
    bool bValidMailAlias;
 
3575
    size_t nValidMailAlias;
 
3576
    bool   bValidMailAlias;
3277
3577
    char *pValidMailAlias = MakeCanonicalMailAlias
3278
3578
                            (   alias+1,
3279
3579
                                &nValidMailAlias,
3307
3607
    }
3308
3608
#else
3309
3609
    char *pValidMailAliasDesc = pValidMailAlias;
3310
 
    int nValidMailAliasDesc = nValidMailAlias;
 
3610
    size_t nValidMailAliasDesc = nValidMailAlias;
3311
3611
#endif
3312
3612
 
3313
3613
    malias[ma_top]->list[i] = NOTHING;
3324
3624
static void do_malias_list(dbref player, char *alias)
3325
3625
{
3326
3626
    int nResult;
3327
 
    struct malias *m = get_malias(player, alias, &nResult);
 
3627
    malias_t *m = get_malias(player, alias, &nResult);
3328
3628
    if (nResult == GMA_NOTFOUND)
3329
3629
    {
3330
3630
        notify(player, tprintf("MAIL: Alias '%s' not found.", alias));
3345
3645
    safe_tprintf_str(buff, &bp, "MAIL: Alias *%s: ", m->name);
3346
3646
    for (int i = m->numrecep - 1; i > -1; i--)
3347
3647
    {
3348
 
        const char *p = Name(m->list[i]);
 
3648
        const char *p = Moniker(m->list[i]);
3349
3649
        if (strchr(p, ' '))
3350
3650
        {
3351
3651
            safe_chr('"', buff, &bp);
3364
3664
    free_lbuf(buff);
3365
3665
}
3366
3666
 
3367
 
static char *Spaces(unsigned int n)
 
3667
static char *Spaces(size_t n)
3368
3668
{
3369
3669
    static char buffer[42] = "                                         ";
3370
 
    static unsigned int nLast = 0;
 
3670
    static size_t nLast = 0;
3371
3671
    buffer[nLast] = ' ';
3372
3672
    if (n < sizeof(buffer)-1)
3373
3673
    {
3382
3682
    bool notified = false;
3383
3683
    for (int i = 0; i < ma_top; i++)
3384
3684
    {
3385
 
        struct malias *m = malias[i];
 
3685
        malias_t *m = malias[i];
3386
3686
        if (  m->owner == GOD
3387
3687
           || m->owner == player
3388
3688
           || God(player))
3397
3697
                               m->name,
3398
3698
                               m->desc,
3399
3699
                               pSpaces,
3400
 
                               Name(m->owner));
 
3700
                               Moniker(m->owner));
3401
3701
            notify(player, p);
3402
3702
        }
3403
3703
    }
3516
3816
        {
3517
3817
            if (p != tolist)
3518
3818
            {
3519
 
                *p++ = ' ';
 
3819
                safe_chr(' ', tolist, &p);
3520
3820
            }
3521
3821
            memcpy(p, head, tail-head);
3522
3822
            p += tail-head;
3539
3839
        head = list;
3540
3840
        while (*head)
3541
3841
        {
3542
 
            while (*head == ' ')
 
3842
            while (' ' == *head)
3543
3843
            {
3544
3844
                head++;
3545
3845
            }
3631
3931
    char *bufDest = alloc_lbuf("do_mail_quick");
3632
3932
    char *bpSubject = bufDest;
3633
3933
 
3634
 
    strcpy(bpSubject, arg1);
 
3934
    mux_strncpy(bpSubject, arg1, LBUF_SIZE-1);
3635
3935
    parse_to(&bpSubject, '/', 1);
3636
3936
 
3637
3937
    if (!bpSubject)
3663
3963
    }
3664
3964
    else
3665
3965
    {
3666
 
        char *mailmsg = atr_get(player, A_MAILMSG, &aowner, &aflags);
3667
 
        if (*mailmsg == '\0')
 
3966
        char *pMailMsg = atr_get(player, A_MAILMSG, &aowner, &aflags);
 
3967
        if (*pMailMsg == '\0')
3668
3968
        {
3669
3969
            notify(player, "MAIL: The body of this message is empty.  Use - to add to the message.");
 
3970
            free_lbuf(tolist);
3670
3971
        }
3671
3972
        else
3672
3973
        {
3673
3974
            char *mailsub   = atr_get(player, A_MAILSUB, &aowner, &aflags);
3674
3975
            char *mailflags = atr_get(player, A_MAILFLAGS, &aowner, &aflags);
3675
 
            mail_to_list(player, tolist, mailsub, mailmsg, flags | mux_atol(mailflags), false);
 
3976
            mail_to_list(player, tolist, mailsub, pMailMsg, flags | mux_atol(mailflags), false);
3676
3977
            free_lbuf(mailflags);
3677
3978
            free_lbuf(mailsub);
3678
3979
 
3679
3980
            Flags2(player) &= ~PLAYER_MAILS;
3680
3981
        }
3681
 
        free_lbuf(mailmsg);
 
3982
        free_lbuf(pMailMsg);
3682
3983
    }
3683
3984
}
3684
3985
 
3688
3989
    notify(player, "MAIL: Message aborted.");
3689
3990
}
3690
3991
 
3691
 
void do_prepend(dbref executor, dbref caller, dbref enactor, int key, char *text)
 
3992
void do_prepend(dbref executor, dbref caller, dbref enactor, int eval, int key, char *text)
3692
3993
{
3693
3994
    UNUSED_PARAMETER(key);
3694
3995
 
3710
4011
        char *bpText = bufText;
3711
4012
        char *strText = text+1;
3712
4013
        mux_exec(bufText, &bpText, executor, caller, enactor,
3713
 
                 EV_STRIP_CURLY | EV_FCHECK | EV_EVAL, &strText, (char **)NULL, 0);
 
4014
                 eval|EV_STRIP_CURLY|EV_FCHECK|EV_EVAL, &strText, NULL, 0);
3714
4015
        *bpText = '\0';
3715
4016
 
3716
4017
        dbref aowner;
3746
4047
    }
3747
4048
}
3748
4049
 
3749
 
void do_postpend(dbref executor, dbref caller, dbref enactor, int key, char *text)
 
4050
void do_postpend(dbref executor, dbref caller, dbref enactor, int eval, int key, char *text)
3750
4051
{
3751
4052
    UNUSED_PARAMETER(key);
3752
4053
 
3774
4075
        char *bpText = bufText;
3775
4076
        char *strText = text+1;
3776
4077
        mux_exec(bufText, &bpText, executor, caller, enactor,
3777
 
                 EV_STRIP_CURLY | EV_FCHECK | EV_EVAL, &strText, (char **)NULL, 0);
 
4078
                 eval|EV_STRIP_CURLY|EV_FCHECK|EV_EVAL, &strText, NULL, 0);
3778
4079
        *bpText = '\0';
3779
4080
 
3780
4081
        dbref aowner;
3840
4141
    dbref aowner;
3841
4142
    int aflags;
3842
4143
 
3843
 
    char *mailto  = atr_get(player, A_MAILTO, &aowner, &aflags);
3844
 
    char *mailmsg = atr_get(player, A_MAILMSG, &aowner, &aflags);
3845
 
    char *names   = make_namelist(player, mailto);
 
4144
    char *mailto   = atr_get(player, A_MAILTO, &aowner, &aflags);
 
4145
    char *pMailMsg = atr_get(player, A_MAILMSG, &aowner, &aflags);
 
4146
    char *names    = make_namelist(player, mailto);
3846
4147
 
3847
 
    int iRealVisibleWidth;
 
4148
    size_t iRealVisibleWidth;
3848
4149
    char szSubjectBuffer[MBUF_SIZE];
3849
4150
    ANSI_TruncateToField(atr_get_raw(player, A_MAILSUB),
3850
4151
        sizeof(szSubjectBuffer), szSubjectBuffer, 35,
3851
4152
        &iRealVisibleWidth, ANSI_ENDGOAL_NORMAL);
3852
4153
 
3853
 
    notify(player, DASH_LINE);
3854
 
    notify(player, tprintf("From:  %-*s  Subject: %s\nTo: %s",
3855
 
            PLAYER_NAME_LIMIT - 6, Name(player), szSubjectBuffer, names));
3856
 
    notify(player, DASH_LINE);
3857
 
    notify(player, mailmsg);
3858
 
    notify(player, DASH_LINE);
3859
 
    free_lbuf(mailmsg);
 
4154
    char szFromName[MBUF_SIZE];
 
4155
    GetFromField(player, szFromName);
 
4156
 
 
4157
    notify(player, DASH_LINE);
 
4158
    notify(player, tprintf("From:  %s  Subject: %s\nTo: %s",
 
4159
            szFromName, szSubjectBuffer, names));
 
4160
    notify(player, DASH_LINE);
 
4161
    notify(player, pMailMsg);
 
4162
    notify(player, DASH_LINE);
 
4163
    free_lbuf(pMailMsg);
3860
4164
    free_lbuf(names);
3861
4165
    free_lbuf(mailto);
3862
4166
}
3864
4168
static void do_malias_desc(dbref player, char *alias, char *desc)
3865
4169
{
3866
4170
    int nResult;
3867
 
    struct malias *m = get_malias(player, alias, &nResult);
 
4171
    malias_t *m = get_malias(player, alias, &nResult);
3868
4172
    if (nResult == GMA_NOTFOUND)
3869
4173
    {
3870
4174
        notify(player, tprintf("MAIL: Alias '%s' not found.", alias));
3877
4181
    if (  m->owner != GOD
3878
4182
       || ExpMail(player))
3879
4183
    {
3880
 
        int  nValidMailAliasDesc;
3881
 
        bool bValidMailAliasDesc;
3882
 
        int  nVisualWidth;
 
4184
        size_t nValidMailAliasDesc;
 
4185
        bool   bValidMailAliasDesc;
 
4186
        size_t nVisualWidth;
3883
4187
        char *pValidMailAliasDesc = MakeCanonicalMailAliasDesc
3884
4188
                                    (   desc,
3885
4189
                                        &nValidMailAliasDesc,
3914
4218
    }
3915
4219
 
3916
4220
    int nResult;
3917
 
    struct malias *m = get_malias(player, alias, &nResult);
 
4221
    malias_t *m = get_malias(player, alias, &nResult);
3918
4222
    if (nResult == GMA_NOTFOUND)
3919
4223
    {
3920
4224
        notify(player, tprintf("MAIL: Alias '%s' not found.", alias));
3937
4241
static void do_malias_add(dbref player, char *alias, char *person)
3938
4242
{
3939
4243
    int nResult;
3940
 
    struct malias *m = get_malias(player, alias, &nResult);
 
4244
    malias_t *m = get_malias(player, alias, &nResult);
3941
4245
    if (nResult == GMA_NOTFOUND)
3942
4246
    {
3943
4247
        notify(player, tprintf("MAIL: Alias '%s' not found.", alias));
3992
4296
 
3993
4297
    m->list[m->numrecep] = thing;
3994
4298
    m->numrecep = m->numrecep + 1;
3995
 
    notify(player, tprintf("MAIL: %s added to %s", Name(thing), m->name));
 
4299
    notify(player, tprintf("MAIL: %s added to %s", Moniker(thing), m->name));
3996
4300
}
3997
4301
 
3998
4302
static void do_malias_remove(dbref player, char *alias, char *person)
3999
4303
{
4000
4304
    int nResult;
4001
 
    struct malias *m = get_malias(player, alias, &nResult);
 
4305
    malias_t *m = get_malias(player, alias, &nResult);
4002
4306
    if (nResult == GMA_NOTFOUND)
4003
4307
    {
4004
4308
        notify(player, tprintf("MAIL: Alias '%s' not found.", alias));
4047
4351
    {
4048
4352
        m->numrecep--;
4049
4353
        notify(player, tprintf("MAIL: %s removed from alias %s.",
4050
 
                   Name(thing), alias));
 
4354
                   Moniker(thing), alias));
4051
4355
    }
4052
4356
    else
4053
4357
    {
4054
4358
        notify(player, tprintf("MAIL: %s is not a member of alias %s.",
4055
 
                   Name(thing), alias));
 
4359
                   Moniker(thing), alias));
4056
4360
    }
4057
4361
}
4058
4362
 
4059
4363
static void do_malias_rename(dbref player, char *alias, char *newname)
4060
4364
{
4061
4365
    int nResult;
4062
 
    struct malias *m = get_malias(player, newname, &nResult);
 
4366
    malias_t *m = get_malias(player, newname, &nResult);
4063
4367
    if (nResult == GMA_FOUND)
4064
4368
    {
4065
4369
        notify(player, "MAIL: That name already exists!");
4085
4389
        return;
4086
4390
    }
4087
4391
 
4088
 
    int  nValidMailAlias;
4089
 
    bool bValidMailAlias;
 
4392
    size_t nValidMailAlias;
 
4393
    bool   bValidMailAlias;
4090
4394
    char *pValidMailAlias = MakeCanonicalMailAlias
4091
4395
                            (   newname+1,
4092
4396
                                &nValidMailAlias,
4107
4411
static void do_malias_delete(dbref player, char *alias)
4108
4412
{
4109
4413
    int nResult;
4110
 
    struct malias *m = get_malias(player, alias, &nResult);
 
4414
    malias_t *m = get_malias(player, alias, &nResult);
4111
4415
    if (nResult == GMA_NOTFOUND)
4112
4416
    {
4113
4417
        notify(player, tprintf("MAIL: Alias '%s' not found.", alias));
4158
4462
    notify(player,
4159
4463
      "Num  Name         Description                              Owner");
4160
4464
 
4161
 
    struct malias *m;
 
4465
    malias_t *m;
4162
4466
    int i;
4163
4467
 
4164
4468
    for (i = 0; i < ma_top; i++)
4167
4471
        char *pSpaces = Spaces(40 - m->desc_width);
4168
4472
        notify(player, tprintf("%-4d %-12s %s%s %-15.15s",
4169
4473
                       i, m->name, m->desc, pSpaces,
4170
 
                       Name(m->owner)));
 
4474
                       Moniker(m->owner)));
4171
4475
    }
4172
4476
 
4173
4477
    notify(player, "***** End of Mail Aliases *****");
4186
4490
    }
4187
4491
}
4188
4492
 
4189
 
static void malias_cleanup1(struct malias *m, dbref target)
 
4493
static void malias_cleanup1(malias_t *m, dbref target)
4190
4494
{
4191
4495
    int count = 0;
4192
4496
    dbref j;
4265
4569
    if (*name == '*')
4266
4570
    {
4267
4571
        int pnResult;
4268
 
        struct malias *m = get_malias(player, name, &pnResult);
 
4572
        malias_t *m = get_malias(player, name, &pnResult);
4269
4573
        if (pnResult == GMA_NOTFOUND)
4270
4574
        {
4271
4575
            notify(player, tprintf("MAIL: Mail alias %s not found.", name));
4542
4846
    m_mi->time = NULL;
4543
4847
    MEMFREE(m_mi->tolist);
4544
4848
    m_mi->tolist = NULL;
4545
 
    MEMFREE(m_mi);
 
4849
    delete m_mi;
4546
4850
 
4547
4851
    m_mi = miNext;
4548
4852
    m_bRemoved = true;
4602
4906
        mi->tolist = NULL;
4603
4907
        MEMFREE(mi->time);
4604
4908
        mi->time = NULL;
4605
 
        MEMFREE(mi);
 
4909
        delete mi;
4606
4910
    }
4607
4911
    m_mi = NULL;
4608
4912
}