private async Task <MmsResponse> SendMms(string address, string message, List <Windows.Storage.StorageFile> attachments, MmsPriority priority = MmsPriority.Normal) { Argument.ExpectNotNullOrWhiteSpace(() => message); Argument.ExpectNotNullOrWhiteSpace(() => address); string timeStampStr = "----------------------------" + DateTime.Now.Ticks.ToString("x", CultureInfo.InvariantCulture); string textContent = GetTextContent(timeStampStr, address, message); HttpContent content; if (attachments != null && attachments.Count > 0) { byte[] bytes = await EncodeBinaryContent(attachments, textContent, timeStampStr); content = new ByteArrayContent(bytes); } else { textContent = textContent + "--" + timeStampStr + "--\r\n"; content = new StringContent(textContent); } content.Headers.ContentType = CreateContentTypeHeader(timeStampStr); var requestUri = new Uri(Settings.EndPoint, SendRelativeUrl); string strResponse = await SendContentRequest(HttpMethod.Post, requestUri.ToString(), content); return(MmsResponse.Parse(strResponse)); }
public Mms(string sourcePath, Stream s, long end) { bool stop = false; bool parseParts = false; // header while (s.Position < end) { int type = s.ReadByte(); switch (type) { case 0x8C: // MsgType MessageType messageType = (MessageType)s.ReadByte(); log.AppendFormat("MessageType = {0}\r\n", messageType); break; case 0x8F: // Priority MmsPriority prio = (MmsPriority)s.ReadByte(); log.AppendFormat("Priority = {0}\r\n", prio); break; case 0x98: // TransId log.AppendFormat("TransId = {0}\r\n", ReadTextString(s)); break; case 0x8B: log.AppendFormat("MessageId = {0}\r\n", ReadTextString(s)); break; case 0x8D: // MMS version int verByte = s.ReadByte(); int verMajor = (verByte & 0x70) >> 4; int verMinor = (verByte & 0x0F); log.AppendFormat("MMS version = {0}.{1}\r\n", verMajor, verMinor); break; case 0x89: // From log.AppendFormat("From = {0}\r\n", ReadEncodedString(s)); break; case 0x97: // To log.AppendFormat("To = {0}\r\n", ReadEncodedString(s)); break; case 0x96: // Subject this.subject = ReadEncodedString(s); log.AppendFormat("Subject = {0}\r\n", this.subject); break; case 0x86: // Delivery report log.AppendFormat("Delivery report = {0}\r\n", ReadYesNo(s)); break; case 0x90: // Read reply log.AppendFormat("Read reply = {0}\r\n", ReadYesNo(s)); break; case 0x91: // Report allowed log.AppendFormat("Report allowed = {0}\r\n", ReadYesNo(s)); break; case 0x94: // Sender visibility log.AppendFormat("Sender visibility = {0}\r\n", ReadYesNo(s)); break; case 0x88: // Expiry long expiry = ReadLongInteger(s); log.AppendFormat("Expiry = {0}\r\n", expiry); break; case 0x85: // Date this.time = ReadDateTime(s); log.AppendFormat("Date = {0}\r\n", this.time); break; case 0x8A: // MessageClass log.AppendFormat("Message class = {0}\r\n", ReadMessageClass(s)); break; case 0x84: int contentType = s.ReadByte(); if (contentType <= 31) { /* Content-general-form */ s.Seek(-1, SeekOrigin.Current); ReadValueLength(s); contentType = s.ReadByte(); } string cts = ""; if (contentType > 31 && contentType < 128) { /* Constrained-media - Extension-media*/ s.Seek(-1, SeekOrigin.Current); cts = ReadTextString(s); } else { /* Constrained-media - Short Integer*/ contentType = contentType & 0x7F; /****************************************************************** * A list of content-types of a MMS message can be found here: * * http://www.wapforum.org/wina/wsp-content-type.htm * ******************************************************************/ switch (contentType) { case 0x23: cts = "multipart.mixed"; parseParts = true; break; case 0x33: cts = "multipart.related"; parseParts = true; break; default: cts = "unknown"; break; } } log.AppendFormat("Content type = {0}\r\n", cts); bool noparams = false; while (!noparams) { int testParam = s.ReadByte(); switch (testParam) { case 0x89: testParam = s.ReadByte(); if (testParam < 128) { log.AppendFormat("Start = {0}\r\n", ReadTextString(s)); } else { testParam = testParam & 0x7F; log.AppendFormat("Start = {0}\r\n", testParam.ToString("X")); } break; case 0x8A: testParam = s.ReadByte(); if (testParam < 128) { log.AppendFormat("Param = {0}\r\n", ReadTextString(s)); } else { testParam = testParam & 0x7F; log.AppendFormat("Param = {0}\r\n", testParam.ToString("X")); } break; default: s.Seek(-1, SeekOrigin.Current); noparams = true; break; } } stop = true; break; case 0x99: case 0x9A: int test = s.ReadByte(); if (test < 0x80) { s.Seek(-1, SeekOrigin.Current); log.AppendLine("0x" + type.ToString("X") + " = " + ReadTextString(s)); } else { log.AppendLine("0x" + type.ToString("X") + " = " + test.ToString("X")); } break; default: throw new ApplicationException(string.Format("Unknown field type: 0x{0}", type.ToString("X"))); } if (stop) { break; } } // body if (parseParts) { int partCount = (int)ReadUint(s); log.AppendFormat("PartCnt = {0}\r\n", partCount); for (int i = 0; i < partCount; i++) { long headlen = (long)ReadUint(s); long datalen = (long)ReadUint(s); long ctypepos = s.Position; string ctype; int type = s.ReadByte(); s.Seek(-1, SeekOrigin.Current); if (type <= 31) { ReadValueLength(s); type = s.ReadByte(); s.Seek(-1, SeekOrigin.Current); } if (type > 31 && type < 128) { ctype = ReadTextString(s); } else { switch (type) { case 0x9E: ctype = "image/jpeg"; break; case 0x83: ctype = "text/plain"; break; case 0x87: ctype = "text/x-vCard"; break; default: ctype = "unknown"; break; } } string filename; if (headlen > 4) { filename = ReadTextString(s).TrimStart('?'); } else // no filename present { string ext = ""; switch (ctype) { case "text/plain": ext = ".txt"; break; } filename = string.Format("part_{0}{1}", i + 1, ext); } if (ctype == "application/smil" && !filename.ToLower().EndsWith(".smil")) { filename += ".smil"; } files.Add(new FileInfo(sourcePath, filename, ctypepos + headlen, datalen, this.time)); log.AppendFormat("Part {0}: headLength = {1}, dataLength = {2}, ctype = {3}, filename = {4}\r\n", i + 1, headlen, datalen, ctype, filename); s.Seek(ctypepos + headlen + datalen, SeekOrigin.Begin); } } }
/// <summary> /// Sends new MMS message. /// </summary> /// <param name="phoneNumbers">Phone numbers to send MMS message to.</param> /// <param name="message">Message body to send.</param> /// <param name="attachments">List of files attached to MMS.</param> /// <param name="priority">MMS priority.</param> /// <returns>Instance of <see cref="MmsResponse"/> with sent MMS response information.</returns> /// <exception cref="System.ArgumentNullException">Throws exception when the message is null.</exception> public async Task <MmsResponse> SendMms(IEnumerable <string> phoneNumbers, string message, IEnumerable <Windows.Storage.StorageFile> attachments, MmsPriority priority = MmsPriority.Normal) { Argument.ExpectNotNullOrWhiteSpace(() => message); Argument.ExpectNotNull(() => phoneNumbers); Argument.Expect(() => phoneNumbers.Any(), "phoneNumbers", "at least one phone number is required"); var attachList = attachments == null ? null : attachments.ToList(); var sb = new StringBuilder(); foreach (string pn in phoneNumbers) { sb.AppendFormat(CultureInfo.InvariantCulture, "Address={0}&", Uri.EscapeUriString(PhoneNumberConverter.ConvertToIsdn(pn))); } return(await SendMms(sb.ToString(), message, attachList, priority)); }