Method code for $mail_lib.range_to_actual()

[Turn on line numbering]
arg rng, current;
var start, end, out, listm, m, x, list;

list = current['list];
listm = list.mail();
if (type(rng[1]) == 'integer) {
    start = rng[1];
} else {
    switch (rng[1]) {
        case 'end:
            if (type(rng[2]) != 'symbol)
                throw(~range, "Backwards range.");
            start = current['list].mail().length();
        case 'start:
            start = 1;
        case 'current:
            start = current['location] in listm;
        case 'specific:
            out = [];
            for m in (rng[2].explode_english_list()) {
                if (!(x = toint(m)) || x < 1) {
                    sender().tell("Ignoring list range element '" + m + "'.");
                } else {
                    catch ~range
                        out = setadd(out, (> listm[x] <));
                    with
                        sender().tell("List range #" + x + " is higher than the messages in " + list.mail_name() + " (" + listm.length() + ")");
                }
            }
            return out || throw(~range, "No elements in list range.");
    }
}
if (type(rng[2]) == 'integer) {
    end = rng[2];
} else {
    switch (rng[2]) {
        case 'end:
            end = current['list].mail().length();
        case 'single:
            end = start;
        case 'start:
            throw(~range, "Backwards range.");
        case 'current:
            end = current['location] in current['list].mail();
    }
}
if (start > end)
    throw(~range, "Backwards range.");
out = [];
for m in [start .. end] {
    catch ~range
        out = setadd(out, (> listm[m] <));
    with
        sender().tell("List range #" + m + " is higher than the messages in " + list.mail_name() + " (" + listm.length() + ")");
}
return out || throw(~range, "No elements in list range.");

// Created 27-Mar-1995 as a part of ColdCore, see: @help Credit

Tlon