Beispiel #1
0
static void process_message_callback(GMimeObject *part, gpointer user_data)
{
	struct mime_cbinfo *cbinfo = user_data;

	cbinfo->count++;

	/* We strip off the headers before we get here, so should only see GMIME_IS_PART */
	if (GMIME_IS_MESSAGE_PART(part)) {
		ast_log(LOG_WARNING, "Got unexpected GMIME_IS_MESSAGE_PART\n");
		return;
	} else if (GMIME_IS_MESSAGE_PARTIAL(part)) {
		ast_log(LOG_WARNING, "Got unexpected GMIME_IS_MESSAGE_PARTIAL\n");
		return;
	} else if (GMIME_IS_MULTIPART(part)) {
		GList *l;
		
		ast_log(LOG_WARNING, "Got unexpected GMIME_IS_MULTIPART, trying to process subparts\n");
		l = GMIME_MULTIPART(part)->subparts;
		while (l) {
			process_message_callback(l->data, cbinfo);
			l = l->next;
		}
	} else if (GMIME_IS_PART(part)) {
		const char *filename;

		if (ast_strlen_zero(filename = g_mime_part_get_filename(GMIME_PART(part)))) {
			ast_debug(1, "Skipping part with no filename\n");
			return;
		}

		post_raw(GMIME_PART(part), cbinfo->post_dir, filename);
	} else {
		ast_log(LOG_ERROR, "Encountered unknown MIME part. This should never happen!\n");
	}
}
Beispiel #2
0
static void part_extractor_foreach_callback(GMimeObject *parent, GMimeObject *part, gpointer user_data) {
  PartExtractorData *a_data = (PartExtractorData *) user_data;

  if (GMIME_IS_MESSAGE_PART(part)) {

    if (a_data->recursion_depth < RECURSION_LIMIT) {
      GMimeMessage *message = g_mime_message_part_get_message((GMimeMessagePart *) part); // transfer none
      if (message)
        g_mime_message_foreach(message, part_extractor_foreach_callback, a_data);

    } else {
      g_printerr("endless recursion detected: %d\r\n", a_data->recursion_depth);
      return;
    }

  } else if (GMIME_IS_MESSAGE_PARTIAL (part)) {
    // Save into an array ? Todo: Look into the specs
  } else if (GMIME_IS_MULTIPART (part)) {
    // Nothing special needed on multipart, let descend further
  } else if (GMIME_IS_PART (part)) {

    // We are interested only in the part 0 (counting down by same logic)
    if (a_data->part_id == 0)
      extract_part(part, a_data);

    a_data->part_id--;

  } else {
    g_assert_not_reached();
  }
}
Beispiel #3
0
static void collector_foreach_callback(GMimeObject *parent, GMimeObject *part, gpointer user_data) {
  g_return_if_fail(user_data != NULL);

  PartCollectorData *fdata = (PartCollectorData *) user_data;

  if (GMIME_IS_MESSAGE_PART(part)) {

    if (fdata->recursion_depth++ < RECURSION_LIMIT) {
      GMimeMessage *message = g_mime_message_part_get_message((GMimeMessagePart *) part); // transfer none
      if (message)
        g_mime_message_foreach(message, collector_foreach_callback, user_data);

    } else {
      g_printerr("endless recursion detected: %d\r\n", fdata->recursion_depth);
      return;
    }

  } else if (GMIME_IS_MESSAGE_PARTIAL(part)) {
    // Save into an array ? Todo: Look into the specs
  } else if (GMIME_IS_MULTIPART(part)) {
    // Nothing special needed on multipart, let descend further
  } else if (GMIME_IS_PART(part)) {
    collect_part(part, fdata, GMIME_IS_MULTIPART(parent));
    fdata->part_id++;
  } else {
    g_assert_not_reached();
  }
}
Beispiel #4
0
static void
count_foreach_callback (GMimeObject *parent, GMimeObject *part, gpointer user_data)
{
    int *count = user_data;
    (*count)++;

    /* 'part' points to the current part node that
     * g_mime_message_foreach() is iterating over */

    /* find out what class 'part' is... */
    if (GMIME_IS_MESSAGE_PART (part))
    {
        /* message/rfc822 or message/news */
        GMimeMessage *message;

        /* g_mime_message_foreach() won't descend into
                   child message parts, so if we want to count any
                   subparts of this child message, we'll have to call
                   g_mime_message_foreach() again here. */
        printf("\n===============descend into subparts=================\n");
        message = g_mime_message_part_get_message ((GMimeMessagePart *) part);
        g_mime_message_foreach (message, count_foreach_callback, count);
    }
    else if (GMIME_IS_MESSAGE_PARTIAL (part))
    {
        /* message/partial */

        /* this is an incomplete message part, probably a
                   large message that the sender has broken into
                   smaller parts and is sending us bit by bit. we
                   could save some info about it so that we could
                   piece this back together again once we get all the
                   parts? */
        printf("\n===============partial=================\n");
    }
    else if (GMIME_IS_MULTIPART (part))
    {
        /* multipart/mixed, multipart/alternative,
         * multipart/related, multipart/signed,
         * multipart/encrypted, etc... */

        /* we'll get to finding out if this is a
         * signed/encrypted multipart later... */
        printf("\n===============multipart=================\n");
    }
    else if (GMIME_IS_PART (part))
    {
        /* a normal leaf part, could be text/plain or
         * image/jpeg etc */
        printf("\n===============normal leaf part=================\n");
        printf("====>>>>====>>>>====>>>>Decode start here<<<<====<<<<====<<<<====\n");
        {
#if 0
            printf("\ndecode this normal leaf part================\n" );
            //GMimeStream *stream = g_mime_stream_file_new (stdout);
            //GMimeDataWrapper * content=g_mime_part_get_content_object(part);
            //g_mime_data_wrapper_write_to_stream(content,stream);
#endif
        }
        AnalyseMessageParse((GMimePart*)part);
    }
    else
    {
        printf("\n===============descend not reached=================\n");
        g_assert_not_reached ();
    }
}