Function to extract the first part of a multipart message
355718
def extract_first_part(message, boundary):
    
    first_message = message.split(boundary)[1].lstrip()
    if first_message.endswith(b'\r\n'):
        first_message = first_message[:-2]
    else:
        first_message = first_message[:-1]
    return first_message
907957
def do_rawpart(self, subcmd, opts, message):
        
        client = MdClient(self.maildir, filesystem=self.filesystem)
        partid = getattr(opts, "part", None)
        if not partid:
            client.getrawpart(message, self.stdout)
        else:
            client.getrawpartid(message, partid, self.stdout)
700536
def _get_first_aggregate_text(node_list):
    '''
    
    '''
    if not node_list:
        return ''

    out = []
    for node in node_list[0].childNodes:
        if node.nodeType == dom.Document.TEXT_NODE:
            out.append(node.nodeValue)
    return '\n'.join(out)
652894
function getMD5text(part) {
    var message = '';
    var constants = part.constants.map(function(field) {
      return field.type + ' ' + field.name + '=' + field.raw;
    }).join('\n');

    var fields = part.fields.map(function(field) {
      if (field.messageType) {
        return field.messageType.md5 + ' ' + field.name;
      }
      else {
        return field.type + ' ' + field.name;
      }
    }).join('\n');

    message += constants;
    if (message.length > 0 && fields.length > 0) {
      message += "\n";
    }
    message += fields;
    return message;
  }
65293
function extractParts (str, indexA, indexB) {
	let part = str.substr(indexA, indexB);

	part = part.replace(/</g, '&lt;').replace(/>/g, '&gt;');
	part = part.replace(/\n/g, '<span class="invisible"> \u21A9</span>\n');
	part = part.replace(/\t/g, '<span class="invisible tab">\u2192</span>');
	return part;
}
1091718
def clean_message(message: Message, topmost: bool = False) -> Message:
    
    if message.is_multipart():
        # Don't recurse in already-deleted attachments
        if message.get_content_type() != 'message/external-body':
            parts = message.get_payload()
            parts[:] = map(clean_message, parts)
    elif message_is_binary(message):
        # Don't gut if this is the topmost message
        if not topmost:
            message = gut_message(message)

    return message
913401
function splitOnFirst(str, splitter, callback) {
        var parts = str.split(splitter);
        var first = parts.shift();
        return callback(first, parts.join(splitter));
    }
163961
def extract_mime(self, mime, def_mime='unk'):
        
        self['mime'] = def_mime
        if mime:
            self['mime'] = self.MIME_RE.split(mime, 1)[0]
            self['_content_type'] = mime
20692
def extract_to(rails_message, format: :full)
      to = complex_extract(rails_message.to.first)
      return to[:value] if to[:decoded]

      case format
      when :full
        rails_message[:to].formatted.first
      when :name
        rails_message[:to].address_list.addresses.first.name
      when :address
        rails_message[:to].address_list.addresses.first.address
      end
    end
440796
def process_msg18(fname):
    """"""
    with open(fname, 'r') as infile:
        info = []
        for lineno, line in enumerate(infile):
            parts = line.split('  ')
            try:
                if len(parts) == 8:
                    parts = parts[:6] + [parts[6] + parts[7]]

                var_name, desc, typ, units, rng, prec, byte_range = parts
                start, end = map(int, byte_range.split('-'))
                size = end - start + 1
                assert size >= 4
                fmt = fix_type(typ, size,
                               additional=[('See Note (5)', ('{size}s', 1172))])

                if ' ' in var_name:
                    warnings.warn('Space in {}'.format(var_name))
                if not desc:
                    warnings.warn('null description for {}'.format(var_name))

                var_name = fix_var_name(var_name)
                full_desc = fix_desc(desc, units)

                info.append({'name': var_name, 'desc': full_desc, 'fmt': fmt})

                if (ignored_item(info[-1]) and var_name != 'SPARE'
                        and 'SPARE' not in full_desc):
                    warnings.warn('{} has type {}. Setting as SPARE'.format(var_name, typ))

            except (ValueError, AssertionError):
                warnings.warn('{} > {}'.format(lineno + 1, ':'.join(parts)))
                raise
        return info
1170125
def split_msg(msgs: List[bytes], max_len: int) -> Tuple[str, List[bytes]]:
    """"""
    msg = ""
    while len(msg.encode()) < max_len:
        if len(msg.encode()) + len(msgs[0]) > max_len:
            return msg, msgs
        char = msgs.pop(0).decode()
        # If we have a space within 15 chars of the length limit, split there to avoid words being broken up.
        if char == " " and len(msg.encode()) > max_len - 15:
            return msg, msgs
        msg += char
    return msg, msgs
622195
function getHeader(data, headerStart)
{
  // 'start' position of the header.
  let start = headerStart;
  // 'end' position of the header.
  let end = 0;
  // 'partial end' position of the header.
  let partialEnd = 0;

  // End of message.
  if (data.substring(start, start + 2).match(/(^\r\n)/))
  {
    return -2;
  }

  while (end === 0)
  {
    // Partial End of Header.
    partialEnd = data.indexOf('\r\n', start);

    // 'indexOf' returns -1 if the value to be found never occurs.
    if (partialEnd === -1)
    {
      return partialEnd;
    }

    if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/))
    {
      // Not the end of the message. Continue from the next position.
      start = partialEnd + 2;
    }
    else
    {
      end = partialEnd;
    }
  }

  return end;
}
356044
def extract_parts
      parts_regex = /
        (?:                    # non-capturing group
          \A                |  # start of string OR
          \r\n                 # line break
         )
        (
          --#{Regexp.escape(boundary || "")}  # boundary delimiter
          (?:--)?                             # with non-capturing optional closing
        )
        (?=\s*$)                              # lookahead matching zero or more spaces followed by line-ending
      /x
      parts = raw_source.split(parts_regex).each_slice(2).to_a
      parts.each_with_index { |(part, _), index| parts.delete_at(index) if index > 0 && Utilities.blank?(part) }

      if parts.size > 1
        final_separator = parts[-2][1]
        parts << [""] if final_separator != "--#{boundary}--"
      end
      parts.map(&:first)
    end
222352
private String getFileText() {

        if (m_orderedFilenamesToUpload.size() > 1) {
            return Messages.get().key(Messages.GUI_UPLOAD_FILES_PLURAL_0);
        } else {
            return Messages.get().key(Messages.GUI_UPLOAD_FILES_SINGULAR_0);
        }
    }
633379
def content(self):
        """"""

        if not self.payload:
            return ''

        if self.payload.is_multipart():
            message_bytes = mime_to_bytes(
                self.payload, 0).replace(b'\n', b'\r\n')
            boundary = b'--' + self.payload.get_boundary().encode('utf-8')
            temp = message_bytes.split(boundary)
            temp.pop(0)
            return boundary + boundary.join(temp)
        else:
            content = self.payload.get_payload()
            if isinstance(content, str_cls):
                content = content.encode('utf-8')
            return content
537071
def buildMessage(headers, parts):
    
    message = multipart.MIMEMultipart('alternative')

    for name, value in headers.iteritems():
        name = name.title()
        if name == "From":
            multipart[name] = _encodeAddress(value)
        elif name in ["To", "Cc", "Bcc"]:
            multipart[name] = _encodeAddresses(value)
        else:
            multipart[name] = _encodeHeader(value)

    for partType, part in parts.iteritems():
        mimeText = text.MIMEText(part.encode("utf-8"), partType, "UTF-8")
        message.attach(mimeText.encode())

    return message
1144354
private String getFirstPartOfString(final String source) {

		final int pos = source.indexOf(".");
		if (pos > -1) {

			return source.substring(0, pos);
		}

		return source;
	}