Index: /extensions/Piwecard/admin/admin_configuration.php
===================================================================
--- /extensions/Piwecard/admin/admin_configuration.php	(revision 20340)
+++ /extensions/Piwecard/admin/admin_configuration.php	(revision 20341)
@@ -173,5 +173,5 @@
 $template->assign('ecard_email_message_html', ((isset($configuration['email_message']['html'])) ? $configuration['email_message']['html'] : htmlspecialchars_decode($piwecard->config['email_message']['html'])));
 $template->assign('preview_image', get_root_url().PIWECARD_PATH.'admin/images/image.jpg');
-    
+
 $template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/admin_configuration.tpl');
 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
Index: /extensions/Piwecard/admin/template/admin_configuration.tpl
===================================================================
--- /extensions/Piwecard/admin/template/admin_configuration.tpl	(revision 20340)
+++ /extensions/Piwecard/admin/template/admin_configuration.tpl	(revision 20341)
@@ -24,8 +24,11 @@
 			if (data.stat =='ok') {
 				$("#previewEmail").html(data.result.message);
+				$.each(data.result.style, function(index, value) {
+					document.getElementById(index).setAttribute("style", value);
+				});
 				$.colorbox({
 					inline:true,
 					href:"#previewEmail",
-					onComplete:function(){
+					onComplete: function(style){
 						$("#cboxLoadedContent").css('text-align', 'left');
 					}
Index: /extensions/Piwecard/include/piwecard.class.php
===================================================================
--- /extensions/Piwecard/include/piwecard.class.php	(revision 20340)
+++ /extensions/Piwecard/include/piwecard.class.php	(revision 20341)
@@ -180,5 +180,6 @@
 			
 			if (!empty($page['category'])) {
-				// Gets all upper categories from the image category
+				// Gets all upper categories from the image category to test 
+				//	- if the upper category is activated for this function
 				$query = 'SELECT * FROM '.CATEGORIES_TABLE.' WHERE id = '.pwg_db_real_escape_string($page['category']['id']).';';
 				$cat = pwg_db_fetch_assoc(pwg_query($query));
Index: /extensions/Piwecard/mail/template/mail_html.tpl
===================================================================
--- /extensions/Piwecard/mail/template/mail_html.tpl	(revision 20340)
+++ /extensions/Piwecard/mail/template/mail_html.tpl	(revision 20341)
@@ -6,5 +6,5 @@
 <style>
 {literal}
-body {
+#email_body {
 	font-family: Univers, Helvetica, Optima;
 	font-size:12px;
@@ -13,19 +13,19 @@
 	background-color: #DDDDDD;
 }
-#the_page {
+#the_email {
 	margin: 0px;
 	padding: 0px;
 	text-align: left;
 }
-#content {
+#email_content {
 	margin: 0px;
 	padding: 30px 0px 0px 30px;
 	width: 732px;
 }
-hr {
+.email_hr {
 	width: 632px;
 	margin-left: 0;
 }
-#copyright {
+#email_copyright {
 	font-size: 10px;
 	margin: 0px;
@@ -39,11 +39,11 @@
 </style>
 </head>
-<body>
-	<div id="the_page">
-		<div id="content" class="content">
+<body id="email_body">
+	<div id="the_email">
+		<div id="email_content" class="content">
 			{$MESSAGE_HTML}
 		</div>
-		<div id="copyright">
-			<hr>
+		<div id="email_copyright">
+			<hr class="email_hr" />
 			{'Sent by'|@translate}
 			<a href="{$GALLERY_URL}">{$GALLERY_TITLE}</a>
Index: /extensions/Piwecard/main.inc.php
===================================================================
--- /extensions/Piwecard/main.inc.php	(revision 20340)
+++ /extensions/Piwecard/main.inc.php	(revision 20341)
@@ -77,5 +77,5 @@
 
 function piwecard_ws_add_methods($arr) {
-	require_once('admin/ws_functions.inc.php');
+	require_once('ws/ws_functions.inc.php');
 }
 ?>
Index: /extensions/Piwecard/ws/index.php
===================================================================
--- /extensions/Piwecard/ws/index.php	(revision 20341)
+++ /extensions/Piwecard/ws/index.php	(revision 20341)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/Piwecard/ws/ws_functions.inc.php
===================================================================
--- /extensions/Piwecard/ws/ws_functions.inc.php	(revision 20341)
+++ /extensions/Piwecard/ws/ws_functions.inc.php	(revision 20341)
@@ -0,0 +1,60 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+$service = &$arr[0];
+$service->addMethod('pwg.piwecard.previewEmail', 'piwecard_ws_previewEmail',
+	array(
+		'format_message'=>array(),
+		'message'=>array(),
+	),
+	'Preview the email'
+);
+
+function piwecard_ws_previewEmail($params, $service) {
+	$format_message = $params['format_message'];
+	$message = $params['message'];
+	
+	return previewEmail($format_message, $message);
+}
+
+function previewEmail($format_message, $message) {
+	$piwecard = new Piwecard();
+
+	$template_mail = new Template(PIWECARD_MAIL_PATH.'template');
+	$smarty = $template_mail->smarty;
+	
+	if ($format_message == 'text') {
+		$message_output = nl2br($piwecard->get_text_message($message, $smarty));
+		$style = '';
+	} elseif ($format_message == 'html') {
+		$output = $piwecard->get_html_message($message, $smarty);
+		$dom_document = new DOMDocument();
+		$dom_document->loadHTML($output);
+		$style = piwecard_create_style_array($dom_document->getElementsByTagName('style')->item(0)->nodeValue);
+		$message_output = $dom_document->saveHTML($dom_document->getElementsByTagName('body')->item(0));
+		$message_output = '<div id="email_body">'.$message_output.'</div>';
+	}
+
+	return array('message' => $message_output, 'style' => $style);
+}
+
+function piwecard_create_style_array($style) {
+	$style = str_replace(array("\n", "\t"), array('', ''), $style);
+	$tok = strtok($style, "{}");
+	
+	$sarray = array();
+	while ($tok !== false) {
+		array_push($sarray, trim($tok));
+		$tok = strtok("{}");
+	}
+
+	$styles = array();
+
+	for($i = 0; $i<count($sarray)-2; $i+=2){
+		$styles[$sarray[$i]] = $sarray[$i+1];
+	}
+
+	return $styles;
+}
+?>
