* Parses a Q encoded word * * @param encodedWord
(encodedWord)
| 143 | * @param encodedWord |
| 144 | */ |
| 145 | parseQEncodedWord(encodedWord) { |
| 146 | let decodedWord = ""; |
| 147 | for (let i = 0; i < encodedWord.length; i++) { |
| 148 | if (encodedWord[i] === "_") { |
| 149 | decodedWord += " "; |
| 150 | // Parse hex encoding |
| 151 | } else if (encodedWord[i] === "=") { |
| 152 | if ((i + 2) >= encodedWord.length) throw new OperationError("Incorrectly Encoded Word"); |
| 153 | const decodedHex = Utils.byteArrayToChars(fromHex(encodedWord.substring(i + 1, i + 3))); |
| 154 | decodedWord += decodedHex; |
| 155 | i += 2; |
| 156 | } else if ( |
| 157 | (encodedWord[i].charCodeAt(0) >= " ".charCodeAt(0) && encodedWord[i].charCodeAt(0) <= "~".charCodeAt(0)) || |
| 158 | encodedWord[i] === "\n" || |
| 159 | encodedWord[i] === "\r" || |
| 160 | encodedWord[i] === "\t") { |
| 161 | decodedWord += encodedWord[i]; |
| 162 | } else { |
| 163 | throw new OperationError("Incorrectly Encoded Word"); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return decodedWord; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | export default MIMEDecoding; |
no test coverage detected