My bad MIME: Obj-C code, but Questiin is not language specific - very complicated

I use the following dictionary to create a MIME header to send an email that attaches a text file. He issues an email under the code. Why is everything distorted? Any MIME experts?

Also, the answer is not as simple as you encode Base64. If I change it from "inline" to "attachment", the email attachment is corrupted when sent to Web Gmail, but the file is fine and can be opened normally if it goes through GMail but Mail opens on Mac. In addition, if the text file is very small, it also works fine on GMail.

Here is the previous wording of this unanswered question. I modified the code in this example a bit to avoid what, in my opinion, might be red gray: GMail will not open the .txt application created by the iPhone App, depending on the size - I think there is an error in my MIME.

NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:
  @"text/plain", kSKPSMTPPartContentTypeKey,
  @"Hey Kevin,\nHere are some gps readings for you to filter.\nLove,\nTrailBehind", kSKPSMTPPartMessageKey,
  @"8bit", kSKPSMTPPartContentTransferEncodingKey, nil];

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
NSString *gpsFilePath = [[@"/tracks/" stringByAppendingString:[track title]] stringByAppendingString:@"/accelerometerReadings.txt"];
gpsFilePath = [[paths objectAtIndex:0] stringByAppendingString: gpsFilePath];

NSData *fileData = [NSData dataWithContentsOfFile:gpsFilePath];
NSDictionary *attached = [NSDictionary dictionaryWithObjectsAndKeys:
  @"text/plain;", kSKPSMTPPartContentTypeKey,
  @"inline;\r\tfilename=\"accelerometerReadings.txt\"", kSKPSMTPPartContentDispositionKey,
  [fileData encodeBase64ForData], kSKPSMTPPartMessageKey,
  @"base64", kSKPSMTPPartContentTransferEncodingKey, nil];

testMsg.parts = [NSArray arrayWithObjects:plainPart, attached, nil];
[testMsg send];

EMAIL

--SKPSMTPMessage--Separator--Delimiter
Content-Type: text/plain
Content-Transfer-Encoding: 8bit

Hey Kevin,
Here are some gps readings for you to filter.
Love,
TrailBehind
--SKPSMTPMessage--Separator--Delimiter
Content-Disposition: attachment;    filename="track.gpx"
Content-Type: text/plain;
Content-Transfer-Encoding: base64

PD94bWwgdmVyc2lvbj0iM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PjwvdHJrcHQ+CgogICAgICA8dHJrcHQgbGF0PSIzOS4zMTYyMzkiIGxvbj0iLTEyMC4xNjc2MjEiPjwvdHJrcHQ+CgogICAgICA8dHJrcHQgbGF0PSIzOS4zMTYyMzkiIGxvbj0iLTEyMC4xNjc2MjEiPjwvdHJrcHQ+CgogICAgICA8dHJrcHQgbGF0PSIzOS4zMTYyMTQiIGxvbj0iLTEyMC4xNjc1MDkiPjwvdHJrcHQ+CgogICAgICA8dHJrcHQgbGF0PSIzOS4zMTYyMDgiIGxvbj0iLTEyMC4xNjczNjgiPjwvdHJrcHQ+CgogICAgICA8dHJrcHQgbGF0PSIzOS4zMTYyMTUiIGxvbj0iLTEyMC4xNjcyOTciPjwvdHJrcHQ+CgogICAgICA8dHJrcHQgbGF0PSIzOS4zMTYyMTUiIGxvbj0iLTEyMC4xNjcyOTciPjwvdHJrcHQ+CgogICAgICA8dHJrcHQgbGF0PSIzOS4zMTYxOTQiIGxvbj0iLTEyMC4xNjcxODEiPjwvdHJrcHQ+CgogICAgICA8dHJrcHQgbGF0PSIzOS4zMTYwNzciIGxvbj0iLTEyMC4xNjcyNTMiPjwvdHJrcHQ+CgogICAgICA8dHJrcHQgbGF0PSIzOS4zMTYwMzIiIGxvbj0iLTEyMC4xNjcyMzQiPjwvdHJrcHQ+CgogICAgICA8dHJrcHQgbGF0PSIzOS4zMTU5ODMiIGxvbj0iLTEyMC4xNjcxOTEiPjwvdHJrcHQ+CgogICAgPC90cmtzZWc+CiAgPC90cms+CjwvZ3B4Pgo=
--SKPSMTPMessage--Separator--Delimiter

--SKPSMTPMessage--Separator--Delimiter--
+3
source share
1 answer

If it looks what your Base64 looks like, it is wrong; it should be wrapped in 76-character strings for email. In addition, it looks like something added space (perhaps due to it not wrapped)

? , , (7 )... MIME. , .

(, " " gmail) RFC 2045 §6 §6.8 .

, , .

+2

Source: https://habr.com/ru/post/1712917/


All Articles