[gmime] added g_mime_part_get_best_content_encoding()



commit 36ac5c03d4c189cc53df16d24e142d2c4726e46c
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Tue Apr 28 22:25:50 2009 -0400

    added g_mime_part_get_best_content_encoding()
    
    2009-04-28  Jeffrey Stedfast  <fejj novell com>
    
    	* gmime/gmime-part.c (g_mime_part_get_best_content_encoding): New
    	helper function to calculate the most efficient
    	Content-Transfer-Encoding for a given mime-part.
---
 ChangeLog                         |    8 ++++++
 TODO                              |   11 +++++++-
 docs/reference/gmime-sections.txt |    1 +
 gmime/gmime-filter-best.c         |   13 +++++-----
 gmime/gmime-filter-best.h         |    6 ++--
 gmime/gmime-part.c                |   46 ++++++++++++++++++++++++++++++++++--
 gmime/gmime-part.h                |    9 +++++--
 7 files changed, 77 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6c09a92..2259191 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,19 @@
 2009-04-28  Jeffrey Stedfast  <fejj novell com>
 
+	* gmime/gmime-part.c (g_mime_part_get_best_content_encoding): New
+	helper function to calculate the most efficient
+	Content-Transfer-Encoding for a given mime-part.
+
+2009-04-28  Jeffrey Stedfast  <fejj novell com>
+
 	* build/vs2008/config-win32.h.in: No longer has GMIME_*_VERSION
 	defines - these are all in gmime-version.h now.
 
 	* gmime/gmime-version.h.in: New template for generating
 	gmime-version.h
 
+	* gmime/gmime.h: #include gmime-version.h
+
 	* configure.ac: Renamed from configure.in. Now generates a
 	gmime/gmime-version.h header which contains a macro for checking
 	the GMime version at compile-time. Requested feature from the
diff --git a/TODO b/TODO
index 9933f0f..5663cfa 100644
--- a/TODO
+++ b/TODO
@@ -28,11 +28,18 @@ GMime 2.6 Planning:
 
 - Add GIO-based GMimeStream and bump glib dep to 2.16 [ DONE ]
 
-- Add a g_mime_part_set_best_encoding()?
+- Add a g_mime_part_get_best_content_encoding()? [ DONE ]
 
-- How about a g_mime_part_set_best_charset()? This one could be
+- Rename GMimeBestEncoding enum to GMimeEncodingConstraint? This might
+  be a better name for the enum to reflect what it's actually meant
+  for. Maybe also move it to gmime-encodings.h?
+
+- How about a g_mime_part_get_best_charset()? This one could be
   awkward since it depends on the input text being UTF-8...
 
+- Should either rename g_mime_filter_best_encoding() to get_encoding()
+  or else make sure that GMime.metadata 'fixes' the method name to be
+  GetEncoding so that it will appear as a C# property getter.
 
 
 Other:
diff --git a/docs/reference/gmime-sections.txt b/docs/reference/gmime-sections.txt
index 0d64659..7719505 100644
--- a/docs/reference/gmime-sections.txt
+++ b/docs/reference/gmime-sections.txt
@@ -722,6 +722,7 @@ g_mime_part_set_content_location
 g_mime_part_get_content_location
 g_mime_part_set_content_encoding
 g_mime_part_get_content_encoding
+g_mime_part_get_best_content_encoding
 g_mime_part_set_filename
 g_mime_part_get_filename
 g_mime_part_get_content_object
diff --git a/gmime/gmime-filter-best.c b/gmime/gmime-filter-best.c
index 639c396..f7c96be 100644
--- a/gmime/gmime-filter-best.c
+++ b/gmime/gmime-filter-best.c
@@ -280,16 +280,17 @@ g_mime_filter_best_charset (GMimeFilterBest *best)
 
 /**
  * g_mime_filter_best_encoding:
- * @best: best filter
- * @required: encoding that all data must fit within
+ * @best: a #GMimeFilterBest
+ * @constraint: a #GMimeBestEncoding
  *
- * Calculates the best Content-Transfer-Encoding for the stream
- * filtered through @best that fits within the @required encoding.
+ * Calculates the most efficient Content-Transfer-Encoding for the
+ * stream filtered through @best that fits within the encoding
+ * @constraint.
  *
  * Returns: the best encoding for the stream filtered by @best.
  **/
 GMimeContentEncoding
-g_mime_filter_best_encoding (GMimeFilterBest *best, GMimeBestEncoding required)
+g_mime_filter_best_encoding (GMimeFilterBest *best, GMimeBestEncoding constraint)
 {
 	GMimeContentEncoding encoding = GMIME_CONTENT_ENCODING_DEFAULT;
 	
@@ -298,7 +299,7 @@ g_mime_filter_best_encoding (GMimeFilterBest *best, GMimeBestEncoding required)
 	if (!(best->flags & GMIME_FILTER_BEST_ENCODING))
 		return GMIME_CONTENT_ENCODING_DEFAULT;
 	
-	switch (required) {
+	switch (constraint) {
 	case GMIME_BEST_ENCODING_7BIT:
 		if (best->count0 > 0) {
 			encoding = GMIME_CONTENT_ENCODING_BASE64;
diff --git a/gmime/gmime-filter-best.h b/gmime/gmime-filter-best.h
index 7af9ed2..d682e7d 100644
--- a/gmime/gmime-filter-best.h
+++ b/gmime/gmime-filter-best.h
@@ -60,9 +60,9 @@ typedef enum {
  * @GMIME_BEST_ENCODING_8BIT: The stream data may have bytes with the high bit set, but no null bytes.
  * @GMIME_BEST_ENCODING_BINARY: The stream may contain any binary data.
  *
- * Used with g_mime_filter_best_encoding() as the 'required'
+ * Used with g_mime_filter_best_encoding() as the 'constraint'
  * argument. These values provide a means of letting the filter know
- * what the encoding requirements are for the stream.
+ * what the encoding constraints are for the stream.
  **/
 typedef enum {
 	GMIME_BEST_ENCODING_7BIT,
@@ -126,7 +126,7 @@ GMimeFilter *g_mime_filter_best_new (GMimeFilterBestFlags flags);
 
 const char *g_mime_filter_best_charset (GMimeFilterBest *best);
 
-GMimeContentEncoding g_mime_filter_best_encoding (GMimeFilterBest *best, GMimeBestEncoding required);
+GMimeContentEncoding g_mime_filter_best_encoding (GMimeFilterBest *best, GMimeBestEncoding constraint);
 
 G_END_DECLS
 
diff --git a/gmime/gmime-part.c b/gmime/gmime-part.c
index 502b31a..bf8e7e5 100644
--- a/gmime/gmime-part.c
+++ b/gmime/gmime-part.c
@@ -476,7 +476,7 @@ g_mime_part_set_content_description (GMimePart *mime_part, const char *descripti
  * Returns: the content description for the specified mime part.
  **/
 const char *
-g_mime_part_get_content_description (const GMimePart *mime_part)
+g_mime_part_get_content_description (GMimePart *mime_part)
 {
 	g_return_val_if_fail (GMIME_IS_PART (mime_part), NULL);
 	
@@ -731,6 +731,45 @@ g_mime_part_get_content_encoding (GMimePart *mime_part)
 
 
 /**
+ * g_mime_part_get_best_content_encoding:
+ * @mime_part: a #GMimePart object
+ * @constraint: a #GMimeBestEncoding
+ *
+ * Calculates the most efficient content encoding for the @mime_part
+ * given the @constraint.
+ *
+ * Returns: the best content encoding for the specified mime part.
+ **/
+GMimeContentEncoding
+g_mime_part_get_best_content_encoding (GMimePart *mime_part, GMimeBestEncoding constraint)
+{
+	GMimeStream *filtered, *stream;
+	GMimeContentEncoding encoding;
+	GMimeFilterBest *best;
+	GMimeFilter *filter;
+	
+	g_return_val_if_fail (GMIME_IS_PART (mime_part), GMIME_CONTENT_ENCODING_DEFAULT);
+	
+	stream = g_mime_stream_null_new ();
+	filtered = g_mime_stream_filter_new (stream);
+	g_object_unref (stream);
+	
+	filter = g_mime_filter_best_new (GMIME_FILTER_BEST_ENCODING);
+	g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
+	best = (GMimeFilterBest *) filter;
+	
+	g_mime_data_wrapper_write_to_stream (mime_part->content, filtered);
+	g_mime_stream_flush (filtered);
+	g_object_unref (filtered);
+	
+	encoding = g_mime_filter_best_encoding (best, constraint);
+	g_object_unref (best);
+	
+	return encoding;
+}
+
+
+/**
  * g_mime_part_set_filename:
  * @mime_part: a #GMimePart object
  * @filename: the filename of the Mime Part's content
@@ -762,7 +801,7 @@ g_mime_part_set_filename (GMimePart *mime_part, const char *filename)
  * and if not then checks the "name" parameter in the Content-Type.
  **/
 const char *
-g_mime_part_get_filename (const GMimePart *mime_part)
+g_mime_part_get_filename (GMimePart *mime_part)
 {
 	GMimeObject *object = (GMimeObject *) mime_part;
 	const char *filename = NULL;
@@ -787,6 +826,7 @@ set_content_object (GMimePart *mime_part, GMimeDataWrapper *content)
 	g_object_ref (content);
 }
 
+
 /**
  * g_mime_part_set_content_object:
  * @mime_part: a #GMimePart object
@@ -816,7 +856,7 @@ g_mime_part_set_content_object (GMimePart *mime_part, GMimeDataWrapper *content)
  * Returns: the data-wrapper for the mime part's contents.
  **/
 GMimeDataWrapper *
-g_mime_part_get_content_object (const GMimePart *mime_part)
+g_mime_part_get_content_object (GMimePart *mime_part)
 {
 	g_return_val_if_fail (GMIME_IS_PART (mime_part), NULL);
 	
diff --git a/gmime/gmime-part.h b/gmime/gmime-part.h
index 752dc72..51afd94 100644
--- a/gmime/gmime-part.h
+++ b/gmime/gmime-part.h
@@ -27,6 +27,7 @@
 
 #include <gmime/gmime-object.h>
 #include <gmime/gmime-encodings.h>
+#include <gmime/gmime-filter-best.h>
 #include <gmime/gmime-data-wrapper.h>
 
 G_BEGIN_DECLS
@@ -78,7 +79,7 @@ GMimePart *g_mime_part_new_with_type (const char *type, const char *subtype);
 
 /* accessor functions */
 void g_mime_part_set_content_description (GMimePart *mime_part, const char *description);
-const char *g_mime_part_get_content_description (const GMimePart *mime_part);
+const char *g_mime_part_get_content_description (GMimePart *mime_part);
 
 void g_mime_part_set_content_id (GMimePart *mime_part, const char *content_id);
 const char *g_mime_part_get_content_id (GMimePart *mime_part);
@@ -93,11 +94,13 @@ const char *g_mime_part_get_content_location (GMimePart *mime_part);
 void g_mime_part_set_content_encoding (GMimePart *mime_part, GMimeContentEncoding encoding);
 GMimeContentEncoding g_mime_part_get_content_encoding (GMimePart *mime_part);
 
+GMimeContentEncoding g_mime_part_get_best_content_encoding (GMimePart *mime_part, GMimeBestEncoding constraint);
+
 void g_mime_part_set_filename (GMimePart *mime_part, const char *filename);
-const char *g_mime_part_get_filename (const GMimePart *mime_part);
+const char *g_mime_part_get_filename (GMimePart *mime_part);
 
 void g_mime_part_set_content_object (GMimePart *mime_part, GMimeDataWrapper *content);
-GMimeDataWrapper *g_mime_part_get_content_object (const GMimePart *mime_part);
+GMimeDataWrapper *g_mime_part_get_content_object (GMimePart *mime_part);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]