Skip to content

Commit

Permalink
cleanup the .decodeKludges method and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mithgol committed Jun 16, 2014
1 parent af49a24 commit a1b0e05
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ Before the value is returned, the following replacements are made:

### decodeHeader(header, options)

Uses the encoding (determined by `.encodingFromHeader(header)`) to decode strings from the Buffer properties of the header.
Uses the encoding (determined by `.encodingFromHeader(header)`) to decode strings from the Buffer properties of the header's Subfields.

* If `.encodingFromHeader` returns `null`, `options.defaultEncoding` is used.

Expand Down Expand Up @@ -307,6 +307,26 @@ The same returned object may also have one or more of the following properti

* `timezone` — sender's time zone in `+HHmm` or `-HHmm` form (for example, `-0400`) where `+` may be omitted.

### decodeKludges(header, options)

Does a minor part of what `decodeHeader` does: decodes only the kludge lines.

Uses the encoding (determined by `.encodingFromHeader(header)`) to decode strings from the Buffer properties of the header's Subfields. If `.encodingFromHeader` returns `null`, uses `options` or defaults the same way `decodeHeader` does it.

The kludges are decoded only from the following Subfield types:

* `4 / 'MSGID'` — The ID of the message.
* `5 / 'REPLYID'` — If the message is a reply to some other message, contains the MSGID of that message.
* `7 / 'PID'` — The PID of the program that generated the message.
* `2004 / 'TZUTCINFO'` — Time zone information in `+HHmm` or `-HHmm` form (for example, `-0400`) where `+` may be omitted. (Becomes a `TZUTC` kludge.)
* `2000 / 'FTSKLUDGE'` — other FTS-compliant “kludge” lines.

The other subfields (including `PATH` and `SEEN-BY`) are ignored.

The kludge lines are decoded without the preceding SOH (`Ctrl+A`, `0x01`) code.

The returned value is a string containing all the kludge lines separated by the Unix line endings (`LF`, `'\n'`).

### decodeMessage(header, options, callback)

Using the given header, reads the text of the corresponding message (calling `.readJDT` in the process). Then uses the encoding (determined by `.encodingFromHeader(header)`) to decode the text of the message. Calls `callback(error, messageText)` when the decoding is finished.
Expand Down
26 changes: 0 additions & 26 deletions fidonet-jam.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,6 @@ JAM.prototype.decodeKludges = function(header, decodeOptions){

for( var i = 0; i < header.Subfields.length; i++ ){
switch( header.Subfields[i].LoID ){
case 0: // OADDRESS
break;
case 1: // DADDRESS
break;
case 2: // SENDERNAME
break;
case 3: // RECEIVERNAME
break;
case 4: // MSGID
kludges.push(
'MSGID: ' + header.Subfields[i].Buffer.toString(encoding)
Expand All @@ -516,34 +508,16 @@ JAM.prototype.decodeKludges = function(header, decodeOptions){
'REPLY: ' + header.Subfields[i].Buffer.toString(encoding)
);
break;
case 6: // SUBJECT
break;
case 7: // PID
kludges.push(
'PID: ' + header.Subfields[i].Buffer.toString(encoding)
);
break;
/*
case 8: return 'TRACE'; //break;
case 9: return 'ENCLOSEDFILE'; //break;
case 10: return 'ENCLOSEDFILEWALIAS'; //break;
case 11: return 'ENCLOSEDFREQ'; //break;
case 12: return 'ENCLOSEDFILEWCARD'; //break;
case 13: return 'ENCLOSEDINDIRECTFILE'; //break;
case 1000: return 'EMBINDAT'; //break;
*/
case 2000: // FTSKLUDGE
kludges.push(
header.Subfields[i].Buffer.toString(encoding)
);
break;
case 2001: // SEENBY2D
break;
case 2002: // PATH2D
break;
/*
case 2003: return 'FLAGS'; //break;
*/
case 2004: // TZUTCINFO
kludges.push(
'TZUTC: ' + header.Subfields[i].Buffer.toString(encoding)
Expand Down

0 comments on commit a1b0e05

Please sign in to comment.