Kmail Plus

Version: 1.1
Note: Requires r[fuzzby recognition] or higher.
I've spent a lot of time doing things in KoL that should just be supported natively, and while I'm sure IcePenguin makes some of this easier, I have just never really gotten along with it.

So I made this. It's a nice little messages.ash override that makes message sending much more convenient. However it's not completely finished. There are a few issues with Gift Packages that I haven't decided how best to fix yet, as well as some not-quite-finished features that are semi-supported.

Feature details are in the first few lines of messages.ash, but I think it's best experienced by just poking around.

Ideas/suggestions/feedback all welcome. Anybody wjith CSS history that wants to make it prettier or more elegant feel free to speak up.

Just drop both files into the relay folder and enjoy.

Special thanks to Grotfang for helping beautify it a little.

Ch-ch-ch-changes:
2011.06.17: .9 And now filters don't fail for -1. Which is good.
2011.07.07: 1.0 bugfix for ampersands in messages.
2011.12.25: .1 Fuzzby support! Also, option to include /who in autocomplete. Also, 1.0.
 

Attachments

  • AutoComplete.js
    14.6 KB · Views: 104
  • messages.ash
    48.2 KB · Views: 65
Last edited:

Grotfang

Developer
I really like this. It's a nice concept. I have spent about 20 minutes tonight playing with some of the CSS and changed a couple of things. Firstly, I think a table for the navigation in the left frame isn't quite right since it's not really tabular data being presented, so I made "Compose" a paragraph (no HTML5 support assumed meant that was more appropriate than a heading group), the mailboxes an ordered list (since "Inbox" is certainly top and I imagine you considered the order of the others) and finished with a final paragraph tag for options, then styled. I also made conversation headings a heading (h2) as well as the saved, system, bots and trash mailbox headings. I went with h2 simply because it followed your precedent with the "Inbox" and "Outbox" headings.

I also whacked in my standard table row approach for the "details" rows. Please pick and choose what you like, or disregard it in its entirety. I shall probably fiddle more when I have more time.

Once again, thanks! This is a cute script and I see it being one I use. I've attached the version of messages.ash with my changes :)

View attachment messages.ash
 

Theraze

Active member
Grotfang, your messages.ash attachment is completely hidden due to attaching it inline... after reading your message, I assumed there must be an attachment, but even after reading the message twice, I couldn't spot it. I filter out the bad grammar automatically... somewhat depressing, I know. :) It wasn't until after I selected the first word in your message and hit tab (to select the next link) when I got validation that I was missing an attachment that I actually found it.

If you're going to make something inline, maybe make it its own line? Or just avoid inline entirely, since the only 'benefit' it gives is not knowing how many people downloaded your attachment.
 

Grotfang

Developer
To be honest, I am not sufficiently well versed in these boards to remember these things. I fairly quickly made it have its own line when I noticed my mistake, but it's been a while since I've posted an attachment and I forgot that clicking "Done" is sufficient without clicking the "Insert Inline" button first.
 

slyz

Developer
This is neat, it makes me feel like I'm looking at my kmails in Thunderbird.

I do have one request though: could all the individual messages be shown (in chronological order) in the inbox? As the script stands now, the inbox is more a list of players that have sent you kmails, so to read a kmail you need to select the player, then find the kmail among those that person has sent you.

It would be more practical, I think, to have all the messages in the inbox, and some other way to view only messages from a specific player.

I haven't looked at the actual code yet, and I'm not sure you were looking for ergonomy advice, but I hope this is feasible.

Last thing: perhaps links to trade requests and events should be placed somewhere, since passing through messages.php is the usual way to get to them.

EDIT: Last last thing: PVP messages! Although they are not really important, so I would keep those at the bottom of my to do list.

EDIT2: it looks like getMail() is called twice after each action - this is very noticeable on the slow connection I am currently using because of the calls to getNewMail(). Calling it only once when the "message" link in the top menu is used should save some server hits I think. As long as the user is doing things inside messages.ash, I don't think new messages should be checked for. In any case, there are chat warnings and a "check kmail" link could always be added.

EDIT3: Did you think about changing this to a relay_kmail script ? Then it would really be used like a kmail client !
 
Last edited:

Veracity

Developer
Staff member
In case you are interested: api.php has support for kmail. Specifically for people who want to manipulate it without having to hit the user-visible kmail pages. That might be you.

KoL API

You must log-in and pass a PHPSESSID cookie as a normal player. All resposes are JSON objects, unless you specify another format.

You must provide at least two arguments (the bold ones), and some optional arguments:

what
What you are requesting, options include:
status
Most of what you see on the charpane.
inventory
A list of all item IDs and how many you have
events
Green event messages. Poll this to see if you have kmail, then request with the 'id' in the kmail payload
item
Info about an item the character owns.
kmail
Pass an 'id' to fetch a single kmail, or a count to fetch the latest X

for
A description of your application. Try and put something useful so we can find you if there's an issue. (ex. TabbedChat+by+CDMoyer)

format
What format to return. Supported: json, php. Default: json

count
How many to return, for things that return a list. Defaults to 10, max of 100

id
Which item to return, such as when fetching a single kmail or an item id

since
For events, retrieve all events after this date/time (parseable by strtotime()). If 100 results are returned, you may need to query again, changing since to the date of the last item. (Date/time is parsed as aztime)
We don't have direct ASH support for api.php, yet (although I expect you can visit_url), but if it turns out it would be convenient for us to do so, feel free to suggest it.
 
@Grotfang, when I get some free time, I will probably incorporate most if not all of your changes. Anything regarding making it -look- better is indeed something I'm willing to add. Figuring out the proper CSS for this (and other) project is probably the biggest headache of most my work: I want things to look good, but by no means am I a designer. edit: done. still could use more work, but added yours.

I do have one request though: could all the individual messages be shown (in chronological order) in the inbox?
I could indeed make that an option, probably with its own chronological option separate from the per-user page (or not separate... who knows) All in all, I'm -vastly- looking to expand user customization. edit: added.
perhaps links to trade requests and events should be placed somewhere, since passing through messages.php is the usual way to get to them.

EDIT: Last last thing: PVP messages! Although they are not really important, so I would keep those at the bottom of my to do list.
I have considered PVP I just don't really know what kind of messages are there, not playing myself.
Are they all from System or are they "from" other users? Any messages going the other direction? Do they always arrive in chronological order, or can an older one get inserted after a newer one (like when you Save a message) Can they be Saved? And I have -no- idea how trade is handled so I... may just put in a link to it or something. edit: trade/events added. Still have no idea how PVP messages are formatted/handled.
EDIT2: it looks like getMail() is called twice after each action - this is very noticeable on the slow connection I am currently using because of the calls to getNewMail(). Calling it only once when the "message" link in the top menu is used should save some server hits I think. As long as the user is doing things inside messages.ash, I don't think new messages should be checked for. In any case, there are chat warnings and a "check kmail" link could always be added.
This is something I am working on. I'm trying to find a reliable way to check for messages when there's a chance that one may have come in without making a billion hits to the server. In fact just after posting this I started looking for ways to trim this.

EDIT3: Did you think about changing this to a relay_kmail script ? Then it would really be used like a kmail client !
If you want, you can add "relay_" in front of it and it would behave exactly like that. Indeed, this is what I do while testing.

@Veracity: hmm.. interesting. I had completely forgotten about API.php. I'll have to figure out how that all works as that might make this script like a billion times faster. Passing an ID was something I was looking for (to strengthen Gift Box support) and had no idea how to do. I'll have to see about using the rest.
 
Last edited:

zarqon

Well-known member
Parsing api.php would be a fantastic way to access kmail. This will translate the results of api.php directly into an ASH map of records:

PHP:
record kmessage {
   int id;
   string type;
   int fromid;
   int azunixtime;
   string message;
   int[item] items;
   int meat;
   string fromname;
   string localtime;
};
kmessage[int] mail;
boolean load_kmail() {
   mail.clear();
   matcher k = create_matcher("'id' =\\> '(\\d+)',\\s+'type' =\\> '(.+?)',\\s+'fromid' =\\> '(\\d+)',\\s+'azunixtime' =\\> '(\\d+)',\\s+'message' =\\> '(.+?)',\\s+'fromname' =\\> '(.+?)',\\s+'localtime' =\\> '(.+?)'" ,visit_url("api.php?pwd&what=kmail&format=php&count=100&for=mafiascript"));
   int n;
   while (k.find()) {
      n = count(mail);
      mail[n].id = to_int(k.group(1));
      mail[n].type = k.group(2);
      mail[n].fromid = to_int(k.group(3));
      mail[n].azunixtime = to_int(k.group(4));
      matcher mbits = create_matcher("(.*?)\\<center\\>(.+?)",k.group(5));
      if (mbits.find()) {
         mail[n].meat = extract_meat(mbits.group(2));
         mail[n].items = extract_items(mbits.group(2));
         mail[n].message = mbits.group(1);
      } else mail[n].message = k.group(5);
      mail[n].fromname = k.group(6);
      mail[n].localtime = k.group(7);
   }
}

Well, almost directly. It also safely parses items and meat out of the message.

I'm not sure what the "type" field does -- in all of my kmails so far it just says "normal". Perhaps it contains "gift" for gift packages or "npc" for messages from NPC's (like happened during Crimbo).

EDIT: Bug already fixed -- the above function is now more server-friendly (removed the "refresh inv"). This function, since it is now highly both compact and useful, will be in the next ZLib.
 
Last edited:

slyz

Developer
If you want, you can add "relay_" in front of it and it would behave exactly like that. Indeed, this is what I do while testing.
What I meant was to use the relay_ version as a way to look at the kmails saved in the data files without hitting the server. With perhaps a "check for new maïl" button somewhere.
 
I'm going to be making some changes as to when it checks Outbox/Saved folders (pretty much never) to reduce server load, but it looks as though api.php won't really come in handy in a lot of circumstances.

First, it only works for the Inbox (and potentially PVP). That might be the biggest source of your traffic, but it's only one. This is further mitigated by the 100 kmail limit, which if one looks carefully, can be achieved just the same through the User Viewable kmail interface.
EDIT: For the curious, type= 'giftshop' for items from the Gift Shop (as if that needed explanation)

If it turns out that PVP messages also come through this channel, then that's a hit saved either way, and I'll change it over. And I'll also probably use it for single messages as well.

Oh! Grotfang! So, love your style additions except for one -major- thing. Horizontal scroll bar. I'd rather not restrict scroll, but if you could do me a favor and figure out how to style it so that it simply doesn't happen, that would be -awesome-.
 
Last edited:

T_E

Member
This looks very interesting- I placed both files in my relay folder as instructed above but see no changes in the message section of the relay browser when running Mafia. What am I doing wrong? =(
 

Grotfang

Developer
Oh! Grotfang! So, love your style additions except for one -major- thing. Horizontal scroll bar. I'd rather not restrict scroll, but if you could do me a favor and figure out how to style it so that it simply doesn't happen, that would be -awesome-.

fullw is 100% so margin shouldn't be there in the way it was -- width is calculated first, then the table is shunted 10px to the right; hence the scrollbar. I've changed margin to margin-top so useful behaviour is retained. Also added 20px padding to message text cells and made it so your external link in your update box is a) in a separate paragraph (feel free to change back to linebreak if you disagree) and b) uses target="_blank" so it opens in a new tab instead of within the navigation frame. If I have time tomorrow I might have a look at Compose styling and the options menu. Anything in particular you want doing?

I also changed the default for cell (non-hover) colour from off to #669. The code before was stopping me from changing it in the options panel. Could have been a problem with my data file but it's working okay for me since the change.

Just one question: should the Sent box show who the message was to instead of your character name? Seems like most people probably know their name, but may want to know who the message was to.
 

Attachments

  • messages.ash
    39.2 KB · Views: 41

Grotfang

Developer
This looks very interesting- I placed both files in my relay folder as instructed above but see no changes in the message section of the relay browser when running Mafia. What am I doing wrong? =(

"Preferences >> Browser >> Enable user-scripted relay browser overrides" needs to be checked.
 
fullw is 100% so margin shouldn't be there in the way it was -- width is calculated first, then the table is shunted 10px to the right; hence the scrollbar. I've changed margin to margin-top so useful behaviour is retained. Also added 20px padding to message text cells and made it so your external link in your update box is a) in a separate paragraph (feel free to change back to linebreak if you disagree) and b) uses target="_blank" so it opens in a new tab instead of within the navigation frame. If I have time tomorrow I might have a look at Compose styling and the options menu. Anything in particular you want doing?
Shibby. Thank you! Um.. for the options menu... really any and all help would be awesome (notice in the Filters page the right half is slightly covered... yeah, I'm handicapped.) As for the Compose page.. well... I don't really hate it the way it is, but if you can make it prettier, be my guest. Also, if you hardcode colors into the CSS could you comment after it so I can spot it easier? Danke.
I'm a traditionalist and I made my colors look like my Gmail account. Which is Green on Black. No other colors really (well, since "Label Color" was added there's light green now)

I also changed the default for cell (non-hover) colour from off to #669. The code before was stopping me from changing it in the options panel. Could have been a problem with my data file but it's working okay for me since the change.
from... off? I must have mistyped something, the default shouldn't be "off" but rather... that odd shade of blue I have elsewhere (90d0b0 i think)

Just one question: should the Sent box show who the message was to instead of your character name? Seems like most people probably know their name, but may want to know who the message was to.
Hmm, I haven't seen this, but I'm guessing it's because of the recent change I made to display that box by Message instead of by Correspondent. Will work on that.
 

Grotfang

Developer
from... off? I must have mistyped something, the default shouldn't be "off" but rather... that odd shade of blue I have elsewhere (90d0b0 i think)

I did think of that, and tried that blue first, but it is very pale. You use it in the dropdowns for predictive text, where the paleness is nice, but for text it just made it harder to read. It's your call, though.
 
I did think of that, and tried that blue first, but it is very pale. You use it in the dropdowns for predictive text, where the paleness is nice, but for text it just made it harder to read. It's your call, though.

Feel free to come up with any color scheme you like. Like I said, I have a black background with green text, so the pale was perfectly legible on my screen. I'm considering having a few "themes" or something similar to choose from to auto set a color scheme. And perhaps adding a save feature. Who knows.
 

Grotfang

Developer
That sounds a nice idea. Currently, I'm just working with the defaults, since that's what people see when they first use it (and many won't consider fiddling). What I have noticed is that it is hard to switch to the "thread" view; I can do it if I "Mark as unread", which also changes the layout colours slightly. Is this intentional behaviour?
 
That sounds a nice idea. Currently, I'm just working with the defaults, since that's what people see when they first use it (and many won't consider fiddling). What I have noticed is that it is hard to switch to the "thread" view; I can do it if I "Mark as unread", which also changes the layout colours slightly. Is this intentional behaviour?

I'm not sure, I'd need more specific info. All pages use the same CSS, so the colors should match, unless something in one page is classed that isn't in the other. Probably has to do with the color change on hover, I'm gonna guess.
What do you mean by hard? I can't really think of a really good way to put things in threaded view without going to the options and choosing it... I suppose I could include a link inside each individual message to do go to that mode (something like "view entire conversation" or similar)

What is -not- intentionally is the drop down changing the display mode, so I'll fix that.
 
Top