mail2.12.muf.gz

snippets · 7.7 KB · 2010-03-30

MUF Mail 2.12 (1991-92) by Merlin of Chaos: a mail program.

Download   « Back to the snippets list

(
* Mail 2.12
* <C> 1991, 1992  By Merlin <of Chaos> <Earl Miles>
* <Scrambling algorythm by Bob Blaylock, used with permission.>
*
* FREELY DISTRIBUTABLE.  ANYWHERE.  REALLY.
*
* To be put on a mailing list for future upgrades, please send a message to
* "miles@greyrock.mso.colostate.edu".  You may also send suggestions and bug
* reports.  Or don't if you prefer.  This copyright does require that any
* modifications you make the program not be distributed, and in fact be sent
* to Merlin at the previous address, for reference and possibly inclusion into
* future versions.  <i.e, I let you play with my software, you give me your
* mods to it.  Fair enough?  I didn't think so.>
*
* It used to be that unauthorized distribution was punishable by 
* tinycastration.  Well, that not only no longer applies <to this or
* any earlier version> but I wouldn't have done it anyway.
*
* This program has acquired a case of the feeping creatures.  I really don't
* know where they came from, but they struck.  And it's fulluv'em.
*
* *************************************************************************
* ************************ To install Mail ******************************** 
* *************************************************************************
*
* You could use a good date primitive.  Modify the ": datestr" word to set
* up a datestring in whatever format you prefer.  The current word is
* the standard for most systems, but this varies from muck to muck.
*
* If your system does not have a "prog" primitive, or it's different, you
* need to modify the ": newobj" word to point to the correct place to store
* mail.
*
* If you are using Foxen's 2.2fb code, or derivative thereof, or in fact
* any version of the code with PROPDIRs, then you should modify the
* ": DIR" word to point to the directory mail should be kept in.
*
* If you desire mail to be scrambled so that wizards cannot easily read
* mail by examining the storage object, you must 
* 
* "@set <program> = scramble?: yes"
*
* NOTE THAT SCRAMBLING WILL TEND TO CAUSE THE MAIL SYSTEM TO BE SLOWER,
* AND CAN CAUSE SLIGHT TO MEDIUM PERFORMANCE DECRASES ON THE ENTIRE MUCK
* WHENEVER THE MAIL SYSTEM IS USED.  You have been warned.
*
* If your system has a TOLOWER primitive, replace the macro
* ".downcase" with it in the word ": dcase" as it will cause a slight
* speed increase.
*
* @link a global command called 'mail' to this program.
* If you have a connect action which gets called everytime a player connects,
* call the program with the option "-n" or "-new".  It will inform the
* player logging in if they have mail.
*
* If you set a '.alias' property on a command linked to the program, it
* will take that as an argument instead of what was typed in.
* Useful for making mail-by-name-aliases, such as 'mail wizards'.
* Note that you can mail directly to player numbers, as well, so a
* .alias of "#1 #2 #3 #4" would mail to the first 4 people on the DB,
* no matter what their names are.
*
* If the mail program is @locked to a room, it will tell a player if they
* have new mail upon entering.  The lock will always succeed, and will not
* say anything if there is no mail waiting for them.
*
* The program is secure.  Mail cannot be forged, and mail cannot be read
* by other users without wizard permission.  However, NO mail system
* can be secure from WIZARDS.  So if your Muck does not have wizards 
* completely above question <Like ANY Muck does> PLEASE inform the users
* using mail that mail is not TOTALLY private and only MOSTLY private.
* <No jokes about frisking it for loose change, please.>
* Enjoy!
)
: getread ( -- s ) ( read a string; has some debugging stuff )
  read dup "" stringcmp not if pop " " then
  (        ---- The following code is VERY useful for debugging ----
  dup "@showstack" stringcmp not if
    pop
    trigger @ getlink dup "D" set "!D" set
    getread
    exit
  then
  dup "@trace" stringcmp not if
    pop
    trigger @ getlink dup "D" flag? if "!D" else "D" then set
    getread
    exit
  then
  dup "@trace on" stringcmp not if
    pop
    trigger @ getlink "D" set
    getread
    exit
  then
  dup "@trace off" stringcmp not if
    pop
    trigger @ getlink "!D" set
    getread
    exit
  then
  )
;
: VERSION "2.12" ; ( define )
 
: DIR "." ; ( define )
 
: mygetpropstr ( d s -- s )   ( adds a "." to all props )
  DIR swap strcat getpropstr
;
: myremove_prop ( d s -- )    ( adds a "." to all props )
  DIR swap strcat remove_prop
;
: myaddprop ( d s s i -- )      ( adds a "." to all props )
  rot DIR swap strcat rot rot addprop
;
: dcase ( s -- s ) ( basically a define )
  .downcase
;
: readnew? ( -- i )
  trigger @ me @ intostr "rn" strcat getpropstr atoi not
;
: newobj ( -- d )  ( This is the number of the object mail is stored on )
  prog
;
: expert? ( -- i )
  newobj me @ intostr "-x" strcat mygetpropstr "" stringcmp
;
: datestr ( -- s ) ( return a datestring. )
  systime ctime
;
: oldobj ( -- d )
  newobj me @ intostr "-mailobj" strcat mygetpropstr atoi dbref
  dup ok? not if pop me @ exit then
  dup owner me @ dbcmp not if pop me @ then
;
: mailobj ( -- d )
  readnew? if newobj else oldobj then
  dup #0 dbcmp if pop me @ then
;
: messages ( d -- i ) ( How many messages does player d have? )
  mailobj swap intostr "-msgs" strcat mygetpropstr atoi
;
: messagelines ( d i -- i ) ( How many lines does message i have? )
  swap intostr "-" strcat swap intostr strcat "-msg-lines" strcat
  mailobj swap mygetpropstr atoi
;
: rangelines ( d s -- i )
  "lines" strcat mygetpropstr atoi
;
: ranglines ( d s -- i ) ( One that doesn't use mygetpropstr)
  "lines" strcat getpropstr atoi
;
: getprop ( d i s -- s ) ( Get property s of message i to player d )
  swap rot intostr "-" strcat swap intostr strcat "-" strcat swap strcat
  mailobj swap mygetpropstr
;
: remprop ( d i s -- s ) ( Remove property s of message i to player d )
  swap rot intostr "-" strcat swap intostr strcat "-" strcat swap strcat
  mailobj swap myremove_prop
;
: putprop ( d i s1 s2 -- ) ( Put s2 in property s1 of message i to player d )
  4 rotate intostr "-" strcat 4 rotate intostr strcat "-" strcat rot strcat 
  mailobj swap rot 1 myaddprop
;
: rmloop ( d i i -- ) ( player to, mesg #, and a counter )
  dup 0 = if pop exit then
  over over swap intostr "-" strcat swap intostr strcat "-msg-" strcat
  over intostr strcat mailobj swap myremove_prop
  1 -
  rmloop
;
: remmesg ( d i -- ) ( Delete a basic message )
  over over over over messagelines rmloop
  swap intostr "-" strcat swap intostr strcat "-msg-lines" strcat
  mailobj swap myremove_prop
;
: pad ( s i -- s ) ( string to pad, to xx characters.  Maximum of about 70)
  swap over 2 - strcut pop dup strlen rot swap -
  "                                                                     "
  swap strcut pop strcat
;
: dbname ( d -- s ) ( Safely get the name of an object )
  dup ok? not if pop "<garbage>" else name then
;
: screensize ( -- i )
  me @ "screensize" getpropstr atoi dup 0 = if pop 22 then
;
: moreprompt ( -- i )
  me @ "-- More -- [y/n]" notify
  getread
  1 strcut pop
  "n" stringcmp not if 0 else 1 then
;
(
* <scramble-loop and scramble excerpted from> scramble.pgm
*
* A MUF circular scrambler.
* 
* It scrambles a string, or unscrambles a scrambled string.  But it can't
* unscramble an egg.
*
* Algorythm by Bob Blaylock, cleaned up by Merlin <of Chaos> mostly for Mail.
* <Yea, this program.> 
* --- Cut here ---
)
: scramble? ( -- i ) ( Checks a property to see if it should scramble. )
  newobj "scramble?" getpropstr "" stringcmp
;
: scramble-loop ( s s -- s )
  dup strlen 3 < if strcat exit then
  3 strcut rot rot swap strcat swap
  scramble-loop
;
: scramble ( s -- s )
  scramble? not if exit then ( Line added so scramble can be an option )
  "" swap scramble-loop
;
: trim-spaces2
  dup dup strlen swap " " rinstr = if dup strlen 1 - strcut pop trim-spaces2
  then
;
: trim-spaces
  dup strlen 0 = if exit then
  dup swap " " instr 1 = if 1 strcut swap pop trim-spaces then trim-spaces2
;
: cheap-readloop ( d s i -- ) ( object, text, counter )
  dup 4 pick 4 pick ranglines > if pop pop pop exit then
  3 pick 3 pick 3 pick intostr strcat getpropstr me @ swap notify
  dup 7 + screensize % 0 = if moreprompt not if pop pop pop exit then then
  1 +
  cheap-readloop
;
: readloop ( d i i -- ) ( player, message no, counter )
  dup 4 pick 4 pick messagelines > if pop pop pop exit then
  3 pick intostr "-" strcat 3 pick intostr "-msg-" strcat strcat
  over intostr strcat
  mailobj swap mygetpropstr scramble me @ swap notify
  dup 7 + screensize % 0 = if moreprompt not if pop pop pop exit then then
  1 +
  readloop
;
: readmesg ( d i -- ) ( read message #i to player d )
  over intostr "-" strcat over intostr "-msg-1" strcat strcat
  mailobj swap mygetpropstr
  dup "MSGPTR:" 7 strncmp not if
    7 strcut swap pop trim-spaces
    dup " " instr strcut swap atoi dbref swap 1 cheap-readloop
    exit
  then
  pop 1 readloop
;
: sc-copyrangeloop ( -- u d o n t w a n t t o k n o w )
  dup 7 pick + 6 pick > if
    4 pick 4 pick "lines" strcat mygetpropstr atoi + intostr
    4 pick 4 pick "lines" strcat rot 1 myaddprop
    pop pop pop pop pop pop pop exit 
    then
  over over + 
  over 8 pick + 
  10 pick 10 pick rot intostr strcat mygetpropstr scramble 
  6 pick 6 pick 4 rotate intostr strcat rot 1 myaddprop
  1 +
  sc-copyrangeloop
;
: sc-copyrange ( d s i i d s i -- ) ( This is the word which copies a range )
  0 sc-copyrangeloop
;                                   ( It's *very* flexible. )
: copyrangeloop ( -- u d o n t w a n t t o k n o w )
  dup 7 pick + 6 pick > if
    4 pick 4 pick "lines" strcat getpropstr atoi + intostr
    4 pick 4 pick "lines" strcat rot 1 myaddprop
    pop pop pop pop pop pop pop exit 
    then
  over over + 
  over 8 pick + 
  10 pick 10 pick rot intostr strcat mygetpropstr 
  6 pick 6 pick 4 rotate intostr strcat rot 1 myaddprop
  1 +
  copyrangeloop
;
: copyrange ( d s i i d s i -- ) ( This is the word which copies a range )
  0 copyrangeloop                ( of text from one place to another )
;                                ( It's *very* flexible. )
: nodotcopyrangeloop ( -- u d o n t w a n t t o k n o w )
  dup 7 pick + 6 pick > if
    4 pick 4 pick "lines" strcat mygetpropstr atoi + intostr
    4 pick 4 pick "lines" strcat rot 1 addprop
    pop pop pop pop pop pop pop exit 
    then
  over over + 
  over 8 pick + 
  10 pick 10 pick rot intostr strcat getpropstr 
  6 pick 6 pick 4 rotate intostr strcat rot 1 addprop
  1 +
  nodotcopyrangeloop
;
: nodotcopyrange ( d s i i d s i -- ) ( This is the word which copies a range )
  0 nodotcopyrangeloop                ( of text from one place to another )
;                                     ( It's *very* flexible. )
: deleterange ( d s i i -- ) ( object, string, from, to.  And decrement )
                             ( the lines counter to be nice. )
  over over > if
    pop pop
    over over "lines" strcat mygetpropstr atoi 0 = if
      over over "lines" strcat myremove_prop
    then
    pop pop exit 
  then
  4 pick 4 pick 4 pick intostr strcat myremove_prop
  4 pick 4 pick "lines" strcat mygetpropstr atoi 1 - intostr
  5 pick 5 pick "lines" strcat rot 1 myaddprop
  swap 1 + swap
  deleterange
;
: nodotdeleterange ( d s i i -- ) ( object, string, from, to.  And decrement )
                                  ( the lines counter to be nice. )
  over over > if
    pop pop
    over over "lines" strcat getpropstr atoi 0 = if
      over over "lines" strcat remove_prop
    then
    pop pop exit 
  then
  4 pick 4 pick 4 pick intostr strcat remove_prop
  4 pick 4 pick "lines" strcat getpropstr atoi 1 - intostr
  5 pick 5 pick "lines" strcat rot 1 addprop
  swap 1 + swap 
  nodotdeleterange
;
: switch ( -- ) ( switches from reading new to reading saved and )
  readnew? not if
    trigger @ me @ intostr "rn" strcat remove_prop       ( vice )
  else
    trigger @ me @ intostr "rn" strcat "1" 1 addprop     ( versa )
  then
;
: nukefirstword ( s -- s ) ( remove the first word from a string )
  dup " " instr dup not if pop pop "" exit then
  strcut swap pop
;
: validplayer? ( d -- i )
  dup ok? not if pop 0 exit then
  player? not if 0 exit then
  1
;
: popn ( x x i -- ) ( pop x items off the stack. )
  dup 0 = if pop exit then
  swap pop
  1 -
  popn
;
: flagstr ( d -- s ) ( Takes an object, returns a string with flags and dbref
)
  dup name " (#" strcat swap
  dup intostr rot swap strcat swap
  dup room? if swap "R" strcat swap then
  dup player? if swap "P" strcat swap then
  dup program? if swap "F" strcat swap then
  dup "W" flag? if swap "W" strcat swap then
  dup "M" flag? if swap "M" strcat swap then
  dup "L" flag? if swap "L" strcat swap then
  dup "J" flag? if swap "J" strcat swap then
  dup "S" flag? if swap "S" strcat swap then
  dup "D" flag? if swap "D" strcat swap then
  dup "C" flag? if swap "C" strcat swap then
  dup "H" flag? if swap "H" strcat swap then
  dup "A" flag? if swap "A" strcat swap then
  pop
  ")" strcat
;
: makedbrefsloop ( s1 ... si i i2 -- d1 ... di i )
  dup 0 = if pop 1 exit then
  rot dup "" stringcmp not if
    pop swap 1 - swap
  else
    dup match
    dup ok? not if
      pop dup "#" swap strcat match
    else
      dup player? not if
        pop dup "#" swap strcat match
      then
    then
    dup ok? not if
      pop dup "*" swap strcat match 
      me @ "W" flag? not if me @ 1 addpennies then
    else
      dup player? not if
        pop dup "*" swap strcat match
        me @ "W" flag? not if me @ 1 addpennies then
      then
    then
    dup ok? not if
      "Can't find player: " rot strcat me @ swap notify
      rot rot
      0
      exit
    then
    swap pop rot rot
  then
  over 2 + rotate rot rot
  1 -
  makedbrefsloop
;
: makedbrefs ( s -- d1 ... di i ) ( String of names -> list of dbrefs )
  " " explode dup makedbrefsloop dup if exit then
  pop pop popn
  0
;
: maketoloop ( d1 ... di i i s -- d1 ... di i s )
  over 0 = if swap pop exit then
  3 pick 3 + rotate 4 rotate 4 rotate 4 rotate 4 pick dbname " " strcat strcat
  swap 1 - swap
  maketoloop
;
: maketoline ( d1 ... di i -- d1 ... di i s ) ( Turn a list into a string )
  dup "" maketoloop
;
: displayprompt ( -- )
  me @ " " notify
  expert? if 
    me @ "Cmd [?]:" notify
  else
    me @ "#), S)witch, M)ail, L)ist, V)erify, C)hange, E)xpert, Q)uit, H)elp" 
    notify
  then
;
: displaymessageprompt ( -- )
  me @ " " notify
  expert? if
    me @ "Msg Cmd [?]:" notify
  else 
    me @ "S)ave, D)elete, R)eply, C)hange, F)orward, T)ransfer, A)gain, H)elp" 
    notify
  then
;
: displaywaitingloop ( i -- ) ( counter variable )
  dup me @ messages > if pop exit then
  dup intostr " " strcat
  over 10 < if " " swap strcat then
  over me @ swap "from" getprop atoi dbref dup dbname  
    swap validplayer? not if "*" swap strcat then
    20 pad strcat " " strcat
  over me @ swap "date" getprop strcat "  " strcat
  over me @ swap messagelines dup intostr 
  over 100 < if " " swap strcat then
  swap 10 < if " " swap strcat then
  strcat " \"" strcat
  over me @ swap "subj" getprop strcat "\"" strcat
  me @ swap notify
  1 +
  displaywaitingloop
;
: displaywaiting ( -- ) ( Show a player his waiting mail )
  readnew? if "Unread mail:" else "Saved mail:" then 
  me @ swap notify
  me @ " " notify
  me @ messages 0 = if me @ "None." notify exit then 
  1 displaywaitingloop
;
: printversion ( -- )
  me @ "Mail " VERSION strcat " by Merlin <of Chaos>" strcat notify
  me @ "(FTP-able from piggy.ucsb.edu in /pub/mud)" notify
;
: readhelp-main ( -- )
  printversion
  me @ " " notify
  me @ " mail                       -- Reads any mail you have, or saved" notify 
  me @ "                               mail.  Exits if there is no mail." notify  
  me @ " mail <user> <user> ...     -- Sends mail to these users." notify
  me @ " mail -verify <user> <user> -- Tells you if <user>'s have mail." notify
  me @ " mail -change <object>      -- Change your saved mail object to" notify
  me @ "                               <object>" notify
  me @ " mail -display              -- Lists unread mail waiting." notify
  me @ " mail -new                  -- Tells you whether or not you have new mail." notify
  me @ " mail -force                -- Enter the mail system, even if you" notify
  me @ "                               have no mail." notify
  me @ " mail -expert               -- Toggle expert mode." notify
  me @ " mail -help                 -- This file." notify
;
: readhelp-command ( -- )
  printversion
  me @ " " notify
  me @ " #)                         -- Reads that message."
  me @ " S)witch                    -- Switches between reading new and saved" notify
  me @ "                               mail." notify
  me @ " M)ail a user               -- Sends mail to a user." notify
  me @ " V)erify messages           -- Tells you if users have messages." notify
  me @ " C)hange Storage Object     -- Lets you change your 'mail storage'" notify
  me @ "                               object. This object is where all saved" notify
  me @ "                               mail is stored.  Defaults to being" notify
  me @ "                               saved on you." notify
  me @ " L)ist messages             -- Lists mail messages to you." notify
  me @ " E)xpert mode               -- Toggle expert mode." notify
  me @ " H)elp                      -- This file." notify
  me @ " Q)uit                      -- Exit the mail program." notify
  me @ " " notify
  me @ " (mail -help from the command level will give further mail options.)" notify
;
: readhelp-message ( -- )
  printversion
  me @ " " notify
  me @ " R)eply to message          -- Send a message to the author of this" notify
  me @ "                               letter." notify
  me @ " S)ave message              -- Save this message on your mail storage" notify
  me @ "                               object." notify
  me @ " D)elete message            -- Deletes this message, irreversibly." notify
  me @ " C)hange Storage Object     -- Change your mail storage object." notify
  me @ " F)orward message           -- Forward the message to another user." notify
  me @ " T)ransfer message          -- Transfer message to a different mail" notify
  me @ "                               storage object." notify
  me @ " A)gain                     -- Read message again." notify
  me @ " H)elp                      -- This file." notify
;
: sendloop ( ---- same args as sendmessage, 'cept counter is moved )
  dup 0 = if pop pop pop pop pop pop exit then
  7 rotate ( this is who we're sending his copy of the message to.)
  dup messages 1 + intostr over intostr "-msgs" strcat mailobj swap rot
  1 myaddprop   ( increment number of messages. )
  dup dup messages "date" datestr putprop
  dup dup messages "from" 8 pick intostr putprop
  dup dup messages "subj" 9 pick putprop
  dup dup messages "to"  10 pick putprop
  4 pick 4 pick over over rangelines 1 swap
  mailobj 6 pick dup intostr "-" strcat swap messages intostr strcat
  "-msg-" strcat
  1 sc-copyrange
  dup "You sense that you have new mail." notify
  name "Sent to: " swap strcat me @ swap notify
  1 -
  sendloop
;
: sendmessage ( d1 ... di i s s d d s -- ) ( The last one.  Honest. )
                                           ( player list, to-line, subj, )
                                           ( who from, and where msg is )
  6 rotate 
  readnew? not if
    switch sendloop switch
  else
    sendloop
  then
;
: program-send ( d1 ... di i s s d d s -- i )
  3 pick dup me @ dbcmp not swap validplayer? and if 
    pop pop pop pop pop popn exit then 
  over over over over over over ranglines 1 swap 4 rot 4 rot DIR swap strcat 1
  nodotcopyrange
  sendmessage
;
: sendmsg ( d1 ... di i s s -- ) ( player list, to-line and subject )
  trigger @ me @ intostr "-temp" strcat .editor not if
    pop pop popn exit
  then
  trigger @ me @ intostr "-temp" strcat over over ranglines 1 swap
  trigger @ DIR me @ intostr strcat "-temp" strcat 1 nodotcopyrange
  trigger @ me @ intostr "-temp" strcat over over ranglines 1 swap 
  nodotdeleterange
  me @ trigger @ me @ intostr "-temp" strcat
  sendmessage
  trigger @ me @ intostr "-temp" strcat over over rangelines 1 swap
  deleterange
;
: sendmail ( s -- ) ( send mail to player-list in string s )  
  dup "" stringcmp not if
    pop
    me @ "Mail Whom?" notify
    getread
  then
  makedbrefs not if exit then
  maketoline
  me @ "Please enter the subject of this letter:" notify
  getread
  sendmsg
;
: printstorageobject ( -- )
  "Mail storage object is: " oldobj flagstr strcat me @ swap notify
  oldobj me @ dbcmp if
    me @ "ALL SAVED MAIL will be stored on your character.  You should" notify
    me @ "probably @create an object for this use, and C)hange it." notify
  then
;
: matchstorageobject ( s -- d )
  dup match dup int 1 < if pop atoi dbref else swap pop then
  dup owner me @ dbcmp not if
    flagstr me @ swap "You do not own " swap strcat "." strcat notify #-1 
  then
;
: changestorage ( s -- )
  dup "" stringcmp not if
    pop
    printstorageobject
    me @ "Change to?" notify
    getread 
  then
  matchstorageobject dup ok? not if pop exit then
  intostr newobj swap me @ intostr "-mailobj" strcat swap 1 myaddprop
  printstorageobject
;
: verifyloop ( d1 ... di i -- )
  dup 0 = if pop exit then
  swap dup messages swap name " has " strcat over intostr strcat
  " message" strcat swap 1 = not if "s" strcat then "." strcat
  me @ swap notify
  1 - 
  verifyloop
;
: verify ( s -- )
  dup "" stringcmp not if
    pop
    me @ "Who's mail do you wish verified?" notify
    getread
  then
  makedbrefs not if exit then
  readnew? not if
    switch verifyloop switch
  else
    verifyloop
  then
;
: expertmode ( -- )
  expert? if
    newobj me @ intostr "-x" strcat myremove_prop
    me @ "Expert mode off." notify
  else
    newobj me @ intostr "-x" strcat "y" 1 myaddprop
    me @ "Expert mode on." notify
  then
;
  
( modified getprop, remprop, putprop, and messages which allow you to )
( specify which object is being used, instead of relying on readnew? to 
( determine it. )
 
: xgetprop ( d1 d i s -- s ) ( Get property s of message i to player d )
  swap rot intostr "-" strcat swap intostr strcat "-" strcat swap strcat
  mygetpropstr
;
: xremprop ( d1 d i s -- s ) ( Remove property s of message i to player d )
  swap rot intostr "-" strcat swap intostr strcat "-" strcat swap strcat
  myremove_prop
;
: xputprop ( d1 d i s1 s2 -- ) ( Put s2 in property s1 of message i to player d
)
  4 rotate intostr "-" strcat 4 rotate intostr strcat "-" strcat rot strcat 
  swap 1 myaddprop
;
: xmessages ( d1 d -- i ) ( How many messages does player d have? )
  intostr "-msgs" strcat mygetpropstr atoi
;
: decmessages ( d1 d -- ) ( Decrement this msg counter )
  over over xmessages 1 - 
  swap intostr "-msgs" strcat swap intostr 1 myaddprop
;
: copymesgx ( d1 i1 d2 d i2 -- ) ( Msg # i1 on object d1 to obj d2, player d )
  3 pick 3 pick xmessages 1 + intostr 
  3 pick intostr "-msgs" strcat swap 5 pick rot rot 1 myaddprop
  5 pick 5 pick me @ swap "from" xgetprop       ( copy the header )
  4 pick 4 pick 4 pick "from" 5 rotate xputprop
  5 pick 5 pick me @ swap "date" xgetprop
  4 pick 4 pick 4 pick "date" 5 rotate xputprop
  5 pick 5 pick me @ swap "subj" xgetprop
  4 pick 4 pick 4 pick "subj" 5 rotate xputprop
  5 pick 5 pick me @ swap "to" xgetprop
  4 pick 4 pick 4 pick "to" 5 rotate xputprop
  5 pick 5 pick me @ intostr "-" strcat swap intostr strcat "-msg-" strcat
  over over rangelines 1 swap 7 pick 7 pick 7 pick intostr swap intostr "-"
  strcat swap strcat "-msg-" strcat 1 copyrange
  pop pop pop pop pop
;              ( 3 line routine to copy the message itself.  Blah )
: copymesg ( d1 i1 d2 d -- ) ( Mesg # i1 on obj d1 to obj d2, player d )
  over over xmessages 1 + copymesgx
;
: deletemesg ( d1 i -- ) ( delete message i to me @ on object d1 )
  over me @ 3 pick "from" xremprop
  over me @ 3 pick "subj" xremprop
  over me @ 3 pick "date" xremprop
  over me @ 3 pick "to" xremprop
  over over
  intostr me @ intostr "-" strcat swap strcat "-msg-" strcat over over
  rangelines 1 swap deleterange
  over me @ xmessages over > if
    over me @ decmessages
    over over 1 + over me @ 3 pick 1 - copymesgx
    1 + deletemesg
  else
    pop me @ decmessages
  then
;
: savemessage ( i -- ) ( Save and delete msg, if necessary.)
  readnew? if 
    newobj over oldobj me @ copymesg
    newobj swap deletemesg
  then
  me @ "Saved." notify
;
: deletemessage ( i -- ) ( Delete message i )
  mailobj swap deletemesg
  me @ "Deleted." notify
;
: transfermessage ( s i -- ) ( Transfer msg i to object in string s )
  swap dup "" stringcmp not if
    pop
    me @ "To which object would you like to transfer this message?" notify
    getread
  then
  matchstorageobject dup ok? not if pop pop exit then
  mailobj 3 pick 3 rotate me @ copymesg
  mailobj swap deletemesg
  me @ "Transferred." notify
;
: forwardmessage ( s i -- ) ( Forward msg i to player in string s )
  swap dup "" stringcmp not if
    pop
    me @ "Forward this message to whom?" notify
    getread
  then
  .pmatch dup int 1 < if me @ "I can't find that player." notify pop pop
    exit then
  dup me @ dbcmp if me @ "You can't forward to yourself." notify pop pop
    exit then 
  dup "You sense that you have new mail." notify
  swap dup me @ swap "to" getprop "(Fwd to " 
  4 pick dbname strcat " by " strcat me @ name strcat ") " strcat strcat
  over me @ swap "to" 4 rotate putprop
  swap mailobj rot rot newobj swap copymesg 
  me @ "Forwarded." notify
;
: replymessage ( i -- ) ( Which mesage # )
  dup me @ swap "from" getprop atoi dbref
  dup validplayer? not if
    me @ "Unable to reply to message:  Sender is not a player." notify
    pop pop exit
  then
  dup name 1 swap 4 rotate 
  me @ swap "subj" getprop
  dup "RE: " 4 strncmp if
    "RE: " swap strcat
  then
  sendmsg
;
: readmessage ( i -- ) ( read a message. )
  dup me @ swap "from" getprop atoi dbref dup dbname "From: " swap strcat
  swap validplayer? not if " (Non-Player)" strcat then 
  me @ swap notify
  dup me @ swap "to"   getprop "To  : " swap strcat me @ swap notify
  dup me @ swap "date" getprop "On  : " swap strcat me @ swap notify
  dup me @ swap messagelines intostr "Size: " swap strcat me @ swap notify  
  dup me @ swap "subj" getprop "Subj: " swap strcat me @ swap notify
  me @ " " notify
  me @ swap readmesg
;
: interp_message_command ( i s -- i )
  dup dcase "d" 1 strncmp not if pop dup deletemessage 1 exit then
  dup dcase "s" 1 strncmp not if pop dup savemessage  1 exit then 
  dup dcase "r" 1 strncmp not if pop dup replymessage 0 exit then
  dup dcase "a" 1 strncmp not if pop dup readmessage 0 exit then
  dup dcase "c" 1 strncmp not if nukefirstword changestorage 0 exit then
  dup dcase "t" 1 strncmp not if nukefirstword over transfermessage 1 exit then
  dup dcase "f" 1 strncmp not if nukefirstword over forwardmessage 0 exit then
  dup dcase "h" 1 strncmp not if pop readhelp-message 0 exit then
  dup dcase "?" 1 strncmp not if pop readhelp-message 0 exit then
  pop
  me @ "Invalid command." notify 0 exit
;
: messageprompt ( i -- ) ( display a prompt and read/delete/save a msg )
  displaymessageprompt 
  getread
  interp_message_command
  if displaywaiting exit then
  messageprompt
;
: interp_command ( s -- i )
  dup atoi dup 0 = not if
    dup dup me @ messages > swap 0 < or if
      me @ "Invalid message number." notify pop 0 exit
    then
    swap pop dup readmessage messageprompt pop 0 exit
  else
    pop
  then
  dup dcase "s" 1 strncmp not if pop switch displaywaiting 0 exit then
  dup dcase "h" 1 strncmp not if pop readhelp-command 0 exit then
  dup dcase "?" 1 strncmp not if pop readhelp-command 0 exit then
  dup dcase "q" 1 strncmp not if pop 1 exit then
  dup dcase "e" 1 strncmp not if pop expertmode 0 exit then
  dup dcase "c" 1 strncmp not if nukefirstword changestorage 0 exit then
  dup dcase "v" 1 strncmp not if nukefirstword verify 0 exit then
  dup dcase "m" 1 strncmp not if nukefirstword sendmail 0 exit then
  pop displaywaiting 
  0
;
: readmail ( -- )
  displayprompt
  getread
  interp_command if 
    me @ "Mail session over." notify exit then
  readmail
;
: checkmail ( -- )
  me @ messages 0 = not if
    me @ "*** You have new mail ***" notify
  else
    trigger @ exit? if
      me @ "*** You have no mail ***" notify
    then
  then
;
: domail ( -- ) ( Basic entry to mail. )
  printstorageobject
  me @ " " notify
  displaywaiting readmail 
;
: mail ( s -- ) ( The main loop... )
  "me" match me ! ( delete line if me @ is locked ) 
  trigger @ me @ intostr "rn" strcat remove_prop  ( Default to reading new )
  trigger @ ".alias" getpropstr dup "" stringcmp not if
    pop
  else
    swap pop
  then
  
  dup "-n" 2 strncmp not if pop checkmail exit then
  dup "-check" 6 strncmp not if pop checkmail exit then
  dup "-d" 2 strncmp not if pop displaywaiting exit then
  dup "-h" 2 strncmp not if pop readhelp-main exit then
  dup "-v" 2 strncmp not if nukefirstword verify exit then
  dup "-c" 2 strncmp not if nukefirstword changestorage exit then
  dup "-f" 2 strncmp not if pop domail exit then
  dup "-e" 2 strncmp not if pop expertmode exit then
  dup "-ZZRQ" 4 strncmp not if pop program-send exit then
  dup  "-" 1 strncmp not if me @ "mail: Invalid option." notify exit then
  
  trigger @ exit? not if checkmail exit then
  
  dup "" stringcmp not if ( If there is *still* something on the stack) 
                          ( then send mail.  Else read mail. )
    me @ messages 0 = if
      switch me @ messages 0 = if
        me @ "No mail for " me @ name strcat notify
        expert? not if
          trigger @ name dup ";" instr dup if
            1 - strcut then
          pop me @ swap "(Type '" swap strcat " -help' for help.)" strcat
          notify
        then
        exit              ( User had no mail. )
      else
        me @ "No new mail.  Reading saved mail..." notify
        me @ " " notify
      then                ( User had no new mail. )
    then
    domail  
  else
    sendmail
  then
;
: main ( s -- i ) ( actually this is the main loop, but it's real short )
  mail
  trigger @ me @ intostr "rn" strcat remove_prop ( clean up to make sure )
  trigger @ exit? if
    trigger @ getlink "!D" set then              ( JUST in case. )
  1                                              ( make sure lock succeeds )
;

Site Stats

Snippets: 1791
Codebases: 571