Email attachment base64 decoded problem

xiaoxiao2021-03-06  59

1. The base64 encoding of the attachment may contain blank characters (Enter (2 characters), Tab, blank), resulting in not the actual base string length calculated using Length. Such as a string, repeated error, the original string is ended, and finally a carriage return.

In Word, statistics get

The value obtained in debug is 33027, just equal to 32221 403 * 2.

2, base string specified, only A-Z, A-Z, 0-9, / is legal characters, = the tail fill characters, the remaining blank characters (Tab, spaces, Enter, and Renewal) will be ignored. The allowed fill = can only be 0, 1, 2.

3. It is obvious that the fill of the original string is problematic, so it is necessary to remove the blank characters and fillers in the original string and recalculate.

4, However, from the web, foxmail, the attachment files obtained in this program are different, the difference is a few characters! ! ! I don't know who is right?

The code is:

Dim i_add As Integer 'add string length Dim s_content As String' filter s_content = buffer.Substring (start) s_content = s_content.Replace (vbCrLf, "") s_content = s_content.Replace (vbTab, "") s_content = s_content .Replace ("", "") s_content = s_content.replace ("=", ") 'Supplement character number i_add = 4 - (S_Content.Length Mod 4) i_add = IIF (i_add = 4, 0, i_add)' Suppose DIM S_ADD AS STRING = New String ("=", i_add) s_content = s_content & s_add

Me.data = system.convert.frombase64string (s_content)

转载请注明原文地址:https://www.9cbs.com/read-118415.html

New Post(0)