Skip to content

Commit

Permalink
feat(new tool): OVH X-VR-SPAMCAUSE Decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
sharevb committed Jan 12, 2025
1 parent 08d977b commit a7b5022
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as emailNormalizer } from './email-normalizer';
import { tool as xVrSpamcauseDecoder } from './x-vr-spamcause-decoder';

import { tool as asciiTextDrawer } from './ascii-text-drawer';

Expand Down Expand Up @@ -164,7 +165,15 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Network',
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
components: [
ipv4SubnetCalculator,
ipv4AddressConverter,
ipv4RangeExpander,
macAddressLookup,
macAddressGenerator,
ipv6UlaGenerator,
xVrSpamcauseDecoder,
],
},
{
name: 'Math',
Expand Down
12 changes: 12 additions & 0 deletions src/tools/x-vr-spamcause-decoder/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { RecordMail } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'X vr spamcause decoder',
path: '/x-vr-spamcause-decoder',
description: 'Decode X-VR-SPAMCAUSE header in OVH mails',
keywords: ['ovh', 'vade', 'retro', 'vr', 'spam', 'spamcause', 'decoder'],
component: () => import('./x-vr-spamcause-decoder.vue'),
icon: RecordMail,
createdAt: new Date('2024-08-15'),
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, expect, it } from 'vitest';
import { spamCauseDecode } from './x-vr-spamcause-decoder.service';

describe('x-vr-spamcause-decoder', () => {
it('should decode X-VR-SPAMCAUSE', () => {
expect(spamCauseDecode('gggruggvucftvghtrhhoucdtuddrfeelgedrvdduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfenuceurghilhhouhhtmecufedttdenucgohfhorhgsihguuggvnhfjughrucdlhedttddm')).toBe(
'Vade Retro 01.394.21 AS+AV+AP+RT Profile: OVH; Bailout: 300; ^ForbiddenHdr (500)',
);
});
});
24 changes: 24 additions & 0 deletions src/tools/x-vr-spamcause-decoder/x-vr-spamcause-decoder.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function unrot(a: string, b: string, pos: number) {
if (b === undefined) {
return '';
}

if (pos % 2 === 0) {
const c = a;
a = b;
b = c;
}

const offset = ('g'.charCodeAt(0) - a.charCodeAt(0)) * 16;
return String.fromCharCode((a.charCodeAt(0) + b.charCodeAt(0)) - 'x'.charCodeAt(0) - offset);
}

export function spamCauseDecode(text: string) {
let result = '';

for (let n = 0; n < text.length; n += 2) {
result += unrot(text[n], text[n + 1], Math.floor(n / 2));
}

return result;
}
24 changes: 24 additions & 0 deletions src/tools/x-vr-spamcause-decoder/x-vr-spamcause-decoder.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script setup lang="ts">
import { spamCauseDecode } from './x-vr-spamcause-decoder.service';
const encodedXVRSpamCause = ref('');
const decoded = computed(() => spamCauseDecode(encodedXVRSpamCause.value));
</script>

<template>
<div>
<c-input-text
v-model:value="encodedXVRSpamCause"
label="Encoded X-VR-SPAMCAUSE:"
multiline
rows="1"
autosize
placeholder="Your X-VR-SPAMCAUSE header value..."
mb-6
/>

<n-divider />

<textarea-copyable readonly label="Decoded" :value="decoded" />
</div>
</template>

0 comments on commit a7b5022

Please # to comment.